I am trying to decrypt on CryptoJS and encrypt in PyCrypto.
I saw this excellent answer which works like charm, the only problem is that it adjusts PyCrypto to work with CryptoJS, and I prefer to define rules how I expect the input and do as little as possible adjustments on PyCrypto with its defaults.
I thought to ask to send the iv, and with Zero Padding.
I wrote the following in JS (ES6):
const iv = CryptoJS.enc.Hex.parse("1234567889012345");
const key = 'aR1h7EefwlPNVkvTHwfs6w=='
const encrypted = AES.encrypt(
password,
key,
{
iv,
padding: CryptoJS.pad.NoPadding
}
);
const payload = {password: encrypted, iv: iv};
// make HTTPS POST call
Python:
def decrypt_from_cryptoJS(encrypted, iv):
key = "aR1h7EefwlPNVkvTHwfs6w==".encode()
aes = AES.new(key.encode(), AES.MODE_CBC, iv)
encrypted = aes.decrypt(base64.b64decode(encrypted)))
However, I get ValueError: raise TypeError("Object type %s cannot be passed to C code" % type(data))
If I try to create the VI via:
CryptoJS.lib.WordArray.random(16)
and send it via toString() method of JS, I get:
Incorrect IV length (it must be 16 bytes long)
for initiating the AES
How can I decrypt in CryptoJS with minimum code adjustments in PyCrypto? I am not sure I am even going the right way..