为什么解密修改的AES-CBC密文失败解密?
我试图熟悉加密/解密。我正在使用DENO,因为它支持Web Crypto API。
我可以使用AES-CBC加密并解密以获取原始的明文。
我现在正在做的是加密,然后手动修改密文,然后解密。我的期望是,这仍然有效,因为我了解AES-CBC不提供完整性和真实性检查。 (AES-GCM是AEAD的)
但是,当我修改密码文本并尝试解密时,它会失败,但会出现以下错误:
error: Uncaught (in promise) OperationError: Decryption failed
let deCryptedPlaintext = await window.crypto.subtle.decrypt(param, key, asByteArray);
^
at async SubtleCrypto.decrypt (deno:ext/crypto/00_crypto.js:598:29)
at async file:///Users/me/delete/run.js:33:26
AES-CBC是否还具有完整性检查?还是为什么解密失败?
I am trying to get familiar with encryption/decryption. I am using deno as it supports the web crypto API.
I can encrypt and decrypt to get back the original plaintext using AES-CBC.
What I am now doing now is to encrypt, then manually modify the ciphertext and then decrypt. My expectation is that this would still work since I understand that AES-CBC does not provide integrity and authenticity check. (AES-GCM is the one that is AEAD)
But when I modify the cipher text and try to decrypt, it fails with the following error:
error: Uncaught (in promise) OperationError: Decryption failed
let deCryptedPlaintext = await window.crypto.subtle.decrypt(param, key, asByteArray);
^
at async SubtleCrypto.decrypt (deno:ext/crypto/00_crypto.js:598:29)
at async file:///Users/me/delete/run.js:33:26
Does AES-CBC also have integrity checks? Or why is the decryption failing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在Deno中,我在围绕服务器和客户端加密JWT时也有类似的问题,并且由于相同的原因,无法依靠
textDecoder
类:几个小时后我玩耍并找到了一个解决方案,有点棘手,但正在做正确的工作:
解密失败:
对于某些人出于相同目的而依靠课程的人,我建议您使用此解决方案。基础实现在来回转换字符串时(在加密后我需要作为字符串)丢失了一些信息,因此解密失败了。
In Deno I had a similar issue while encrypting a jwt around server and client and could not rely on the
TextDecoder
class for the same reason:After some hours I played around and found a solution, a bit tricky, but is doing the job right:
For some of you relying on the class for the same purpose, I suggest you to use this solution. The underlying implementation pheraps loses some information while converting back and forth the string (I needed it as string after the encryption) and so the decryption fails.