I am trying to decrypt selling partner api reports but while decrypting I am getting this error near decipher.final() [Node] Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
. The api returns the key, iv and the url of the report.
Selling Partner api reference
I tried the solutions mentioned in other threads but still facing issues. I checked the length of both key and iv and it is 32 and 16 respectively.
Here is the code:
var AESCrypt: any = {
decrypt: function (cryptkey: any, iv: any, encryptdata: any) {
var decipher = crypto.createDecipheriv('aes-256-cbc', cryptkey, iv);
// decipher.setAutoPadding(true);
return Buffer.concat([
decipher.update(encryptdata),
decipher.final()
]);
}}
const res = await processRequest({
url: details.url
});
let encrypted_buffer = Buffer.from(res);
const key = Buffer.from(details.encryptionDetails.key, "base64");
const iv = Buffer.from(details.encryptionDetails.initializationVector, "base64");
const decryptedBuff = AESCrypt.decrypt(key, iv, encrypted_buffer);
console.log(decryptedBuff);