Created
March 20, 2014 19:26
-
-
Save matthewhudson/9671831 to your computer and use it in GitHub Desktop.
CoffeeScript Nodejs Cipher
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
crypto = require 'crypto' | |
key = 'monkeybutt' | |
cipher = crypto.createCipher 'aes128', key | |
decipher = crypto.createDecipher 'aes128', key | |
encrypt = (plaintext) -> | |
encrypted = cipher.update plaintext, 'utf8', 'base64' | |
encrypted += cipher.final 'base64' | |
encrypted | |
decrypt = (plaintext) -> | |
decrypted = decipher.update plaintext, 'base64', 'utf8' | |
decrypted += decipher.final 'utf8' | |
decrypted | |
plaintext = JSON.stringify | |
url : '/users/hccopatzkup5' | |
token : 'NURF3MNT3LQUQHP2CVO35FGWMHYQV7AT3KK7Y2RW3R2N6CRZIZ6Q' | |
console.log plaintext | |
encrypted = encrypt(plaintext) | |
decrypted = decrypt(encrypted) | |
console.log 'Encrypted', encrypted | |
console.log 'Decrypted', decrypted | |
console.log 'Are equal?', plaintext is decrypted |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment