Skip to content

Instantly share code, notes, and snippets.

@brainv
Last active August 29, 2015 14:06
Show Gist options
  • Select an option

  • Save brainv/095030eef8cb4d8a88bd to your computer and use it in GitHub Desktop.

Select an option

Save brainv/095030eef8cb4d8a88bd to your computer and use it in GitHub Desktop.
var crypto = require('crypto')
, key = 'your secret key here'
, plaintext = 'Text to be encrypted'
, cipher = crypto.createCipher('aes-256-cbc', key)
, decipher = crypto.createDecipher('aes-256-cbc', key);
var encryptedPassword = cipher.update(plaintext, 'utf8', 'base64');
encryptedPassword += cipher.final('base64')
var decryptedPassword = decipher.update(encryptedPassword, 'base64', 'utf8');
decryptedPassword += decipher.final('utf8');
console.log('original :', plaintext);
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