Skip to content

Instantly share code, notes, and snippets.

@matthewhudson
Created March 20, 2014 19:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save matthewhudson/9671831 to your computer and use it in GitHub Desktop.
Save matthewhudson/9671831 to your computer and use it in GitHub Desktop.
CoffeeScript Nodejs Cipher
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