是否需要初始化向量才能解密我的数据?
我正在使用 RijndaelManaged 来加密和解密数据。我很可能误解了初始化向量的意义,但我发现如果我在解密数据时将其设置为不同的值,则除前 16 个字符外的所有字符仍然可以正确解密。这是预期的行为吗?
I'm using RijndaelManaged to encrypt and decrypt data. I may well have misunderstood the point of an initialization vector, but I am finding that if I set it to a different value when decrypting my data, all but the first 16 characters are still decrypted correctly. Is that expected behaviour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的。在 CBC 模式中,每个密文块用作下一个密文块的 IV。使用错误的 IV 会弄乱第一个 16 字节块,但后续块将不受影响。这可能是一个有用的属性,因为它允许在错误块后进行错误恢复,这在某些情况下可能很重要。它还说明了为什么实际上没有必要对 IV 保密(与密钥不同!)。
Yes. In CBC mode each cyphertext block is used as the IV for the next cyphertext block. Using a faulty IV will mess up the first 16 byte block, but subsequent blocks will be unaffected. This can be a useful property as it allows error recovery after a faulty block, which can be important in some situations. It also illustrates why it is not really necessary to keep the IV secret (unlike the key!).