Skip to content

Instantly share code, notes, and snippets.

@joachimkainz
Created July 23, 2012 18:17
Show Gist options
  • Select an option

  • Save joachimkainz/3165148 to your computer and use it in GitHub Desktop.

Select an option

Save joachimkainz/3165148 to your computer and use it in GitHub Desktop.
encrypt/decrypt with node.js
var SECRET = 'R4@DtoelECf0',
CIPHER = 'aes-256-cbc',
crypto = require('crypto'),
cipher = crypto.createCipher(CIPHER, SECRET),
decipher = crypto.createDecipher(CIPHER, SECRET);
function encrypt(message) {
var crypted = cipher.update(message, 'utf8', 'hex');
return crypted + cipher.final('hex');
}
function descrypt(crypted) {
var message = decipher.update(crypted, 'hex', 'utf8');
return message + decipher.final('utf8');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment