Created
August 8, 2014 03:30
-
-
Save tagomoris/f838f567883e438574a0 to your computer and use it in GitHub Desktop.
This file contains 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 passphrase = new Buffer("xxxxx"); | |
var data = "secret data to protect"; | |
var cipher = crypto.createCipher('aes192', passphrase); | |
cipher.update(data, 'utf8'); | |
var result_buf = cipher.final(); //=> SlowBuffer | |
var result_hex = result_buf.toString('hex'); | |
var input_buf = new Buffer(result_hex, 'hex'); | |
console.log('now decrypting by SlowBuffer'); | |
var decipher1 = crypto.createDecipher('aes192', passphrase); | |
decipher1.update(result_buf); // SlowBuffer | |
var decrypto1 = decipher1.final('utf8'); | |
console.log('now decrypting by Buffer'); | |
var decipher2 = crypto.createDecipher('aes192', passphrase); | |
decipher2.update(input_buf); // Buffer | |
var decrypto2 = decipher2.final('utf8'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment