Skip to content

Instantly share code, notes, and snippets.

@scotttam
Last active December 22, 2015 22:49
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 scotttam/6542922 to your computer and use it in GitHub Desktop.
Save scotttam/6542922 to your computer and use it in GitHub Desktop.
#!/usr/bin/env node
var crypto = require('crypto');
function encode(cryptkey, iv, cleardata) {
var encipher = crypto.createCipheriv('aes-256-cbc', cryptkey, iv),
encoded = encipher.update(cleardata);
encoded = Buffer.concat([encoded, encipher.final()]);
return encoded;
}
var cryptkey = crypto.createHash('sha256').update('Nixnogen').digest(),
iv = 'a2xhcgAAAAAAAAAA',
buf = "Here is some data for the coding", // 32 chars
enc = encode(cryptkey, iv, buf);
function b64enc(data) {
var b = new Buffer(data, 'binary');
return b.toString('base64');
}
console.warn("Encoded length: ", enc.length);
console.warn("Encoded in Base64:", b64enc(enc));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment