Created
February 21, 2013 17:39
-
-
Save renatoargh/5006587 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 = 'this is a secret'; | |
| 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment