Skip to content

Instantly share code, notes, and snippets.

@mikekunze
Created September 25, 2012 22:37
Show Gist options
  • Select an option

  • Save mikekunze/3784884 to your computer and use it in GitHub Desktop.

Select an option

Save mikekunze/3784884 to your computer and use it in GitHub Desktop.
Testing out AES encryption
var crypto = require('crypto')
, key = '0123456789abcd0123456789abcd0123' // 32
, iv = '2345678123456718' // 16
, plaintext = 'password';
var cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
var decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
console.log('key length ' + key.length);
console.log('iv length ' + iv.length);
cipher.setAutoPadding(true);
cipher.update(plaintext, 'utf8', 'hex');
var encryptedPassword = cipher.final('hex')
decipher.update(encryptedPassword, 'hex', '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