Skip to content

Instantly share code, notes, and snippets.

@lsm
Created October 29, 2010 15:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lsm/653787 to your computer and use it in GitHub Desktop.
Save lsm/653787 to your computer and use it in GitHub Desktop.
long string cipher->base64 and decipher
var c = require('crypto');
// cipher to binary
var cipher = c.createCipher('aes192', 'hello');
var en = cipher.update('你好你好你好你好你好dfferfdgwefdv4t5g56euhergy56yhe54wtfgq34tg你好你好你好你好你好你好你好erwgw43etr', 'utf8', 'binary') + cipher.final('binary');
console.log(en);
// binary to base64
var buff = new Buffer(en, 'binary');
var base64 = buff.toString('base64');
console.log(base64);
// base64 to utf8 (decipher)
var decipher = c.createDecipher('aes192', 'hello');
var de = decipher.update(base64, 'base64', 'utf8') + decipher.final('utf8');
console.log(de);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment