Last active
December 22, 2015 22:49
-
-
Save scotttam/6542922 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
#!/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