Skip to content

Instantly share code, notes, and snippets.

@tagomoris
Created August 8, 2014 03:30
Show Gist options
  • Save tagomoris/f838f567883e438574a0 to your computer and use it in GitHub Desktop.
Save tagomoris/f838f567883e438574a0 to your computer and use it in GitHub Desktop.
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