【发布时间】:2015-09-16 03:29:54
【问题描述】:
我正在尝试使用 NodeJS 解密一些数据。
此数据是使用 C# 和 AES-CBC-256 算法创建的。 keySize 和 blockSize 为 256,Padding 为 ZeroPadding。
我不能用 Node.js 解密它,错误是:
Error: error:0606506D:digital envelope routines:EVP_DecryptFinal_ex:wrong final block length
这是我的 javascript 代码:
decipher = crypto.createDecipheriv('aes-256-cbc', key, iv.slice(0, 16));
decrypted = decipher.update(encryptedPayloadBuffer, 'base64', 'ascii');
decrypted += decipher.final('ascii');
decipher = null;
return decrypted;
我使用库“crypto”。我在某处读到 node.js 解密仅适用于 PKSC7 填充。是真的吗? C#项目我什么都改不了,必须在node端找到解决办法。
你能帮帮我吗?
编辑:我试图用这个禁用自动填充:
decipher.setAutoPadding(false);
//next line of code:
//decrypted = decipher.update(encryptedPayloadBuffer, 'base64', 'ascii');
但是我收到了这个错误:
Error: error:0606508A:digital envelope routines:EVP_DecryptFinal_ex:data not multiple of block length
【问题讨论】:
-
如果块大小为 256 位,则不是 AES。请说明您使用的是什么。
-
@ArtjomB。很可能您可以强制 C# AES 实现执行 Rijndael-256,但我不确定。
-
@ArtjomB 我确定它是 AES。这是实现:gist.github.com/VivienAdnot/e9a96fea04bccfa613ec
标签: javascript c# node.js encryption cryptography