Created
April 18, 2014 23:46
-
-
Save jasonsilberman/11068778 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var crypto = require('crypto'); | |
var assert = require('assert'); | |
var algorithm = 'aes256'; // or any other algorithm supported by OpenSSL | |
var key = 'password'; | |
var text = 'I love kittens'; | |
var cipher = crypto.createCipher(algorithm, key); | |
var encrypted = cipher.update(text, 'utf8', 'hex') + cipher.final('hex'); | |
var decipher = crypto.createDecipher(algorithm, key); | |
var decrypted = decipher.update(encrypted, 'hex', 'utf8') + decipher.final('utf8'); | |
assert.equal(decrypted, text); | |
// credit: http://stackoverflow.com/a/6953606/1740273 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment