I've looked at the AES - Encryption with Crypto (node-js) / decryption with Pycrypto (python) post since I'm trying to do the complete opposite but I can't seem to get it right. Here's what I've tried so far ...
Python encryption
import base64
from Crypto import Random
from Crypto.Cipher import AES
text_file = open("cryptic.txt", "w")
pad = lambda s: s + (BS - len(s) % BS) * chr(BS - len(s) % BS)
unpad = lambda s : s[:-ord(s[len(s)-1:])]
plaintxt = 'dolladollabillzz'
iv = Random.new().read( AES.block_size )
print AES.block_size
key = 'totallyasecret!!'
cipher = AES.new(key=key, mode=AES.MODE_CBC, IV=iv)
encrypted = base64.b64encode(iv + cipher.encrypt(plaintxt))
text_file.write(encrypted)
text_file.close()
Node.js decryption
var fs = require('fs');
var crypto = require('crypto');
var Buffer = require('buffer').Buffer;
var algorithm = 'aes-128-cbc';
var key = new Buffer('totallyasecret!!', 'binary');
var cryptic = fs.readFileSync('./cryptic.txt', 'base64');
var iv = cryptic.slice(0, 16);
var ciphertext = cryptic.slice(16);
var decipher = crypto.createDecipheriv(algorithm, key, iv);
var decrypted = [decipher.update(ciphertext)];
decrypted.push(decipher.final('utf8'));
var finished = Buffer.concat(decrypted).toString('utf8');
console.log(finished);
Every time I try to run the Node.js decryption, I end up with the error message:
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length