Created
July 23, 2012 18:17
-
-
Save joachimkainz/3165148 to your computer and use it in GitHub Desktop.
encrypt/decrypt with node.js
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 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