I'm trying to perform AES CBC encryption with zero padding of a url query string. I'm using NodeJS's core crypto module. It's for use with http://www.blackoutrugby.com/game/help.documentation.php#category=35
I have a key and IV. When testing the following function I'm not getting the string returned in full. I believe this has to do with padding but am unsure how to apply it correct.
If it is the padding, can anyone show me how I should apply it? If not where am I going wrong? Also is cipher.final() of significance in this usercase?
Update: I've now included cipher.final() and things work fine with binary format but base64 gives me the truncated result. https://github.com/denishoctor/BlackoutRugbyNode/blob/master/crypto2.js is my full example code. Below is the crypto function:
function cryptoTest(data, key, iv, format) {
var cipher = crypto.createCipheriv('aes-128-cbc', key, iv);
var cipherChunks = [];
cipherChunks.push(cipher.update(data, 'utf8', format));
cipherChunks.push(cipher.final());
var decipher = crypto.createDecipheriv('aes-128-cbc', key, iv);
var plainChunks = [];
for (var i = 0;i < cipherChunks.length;i++) {
plainChunks.push(decipher.update(cipherChunks[i], format, 'utf8'));
}
plainChunks.push(decipher.final());
return {
"encrypted": cipherChunks.join(''),
"decrypted": plainChunks.join('')
};
}
Thanks,
Denis