Skip to content

Instantly share code, notes, and snippets.

@funglaub
Forked from adrianbravo/encrypt-decrypt.js
Created June 21, 2013 22:49
Show Gist options
  • Save funglaub/5834903 to your computer and use it in GitHub Desktop.
Save funglaub/5834903 to your computer and use it in GitHub Desktop.
var crypto = require('crypto')
, key = 'salt_from_the_user_document'
, plaintext = 'password'
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
cipher.update(plaintext, 'utf8', 'base64');
var encryptedPassword = cipher.final('base64')
decipher.update(encryptedPassword, 'base64', 'utf8');
var decryptedPassword = decipher.final('utf8');
console.log('encrypted :', encryptedPassword);
console.log('decrypted :', decryptedPassword);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment