Ok, after a little bit of tinkering, i got the whole thing working.
Here's my code for those who might find it useful:
Updated for 2019 / node 10.15.0
node crypto will handle padding for you.
const crypto = require("crypto");
const iv = crypto.randomBytes(16);
let key = crypto.randomBytes(32);
function encrypt(str) {
const cipher = crypto.createCipheriv('aes-256-cbc', key, iv);
let crypt = cipher.update(str, 'utf8', 'base64');
crypt += cipher.final("base64");
return crypt;
}
function decrypt(str) {
const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv);
let decrypt = decipher.update(str, 'base64', 'utf8');
decrypt += decipher.final();
return decrypt;
}
const enc = encrypt("dude5");
const dec = decrypt(enc);
console.log(enc, dec);