我正在尝试解密销售合作伙伴 api 报告,但在解密时我在 decipher.final() 附近收到此错误[Node] Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
。api 返回报告的键、iv 和 url。
销售伙伴 api 参考
我尝试了其他线程中提到的解决方案,但仍然面临问题。我检查了 key 和 iv 的长度,分别是 32 和 16。
这是代码:
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);