操纵初始化向量不会(真的)阻止我解密 AES 密文

Manipulating the Initialization Vector does not (really) prevent me from decrypting AES ciphertexts

我根据 MSDN 上的示例创建了以下 class: https://gist.github.com/anonymous/19d9e5f6747dfe75d553

每当我这样使用它时,它似乎加密得很好:

var key = Crypto.GenerateKey();
var vector = Crypto.GenerateVector(key);

var cypherText = Crypto.EncryptBase64("abcdefghijklmnopqrstuvwxyz1234567890", key, vector);
vector = Crypto.GenerateVector(key);
var plainText = Crypto.Decrypt(cypherText, key, vector);

然后 plainText 包含以下内容:

�\aU��(���P\u0003�b\u001dxqrstuvwxyz1234567890

所以它似乎改变了 IV,实际上并没有做任何事情(尤其是在较长的文档上)。为什么我们甚至需要静脉注射?

SymmetricAlgorithm 的默认操作模式是 CipherMode.CBC

考虑到 how the CBC mode works 加密数据 IV 的变化将仅影响第一个解密数据块。

引用链接文章:

Decrypting with the incorrect IV causes the first block of plaintext to be corrupt but subsequent plaintext blocks will be correct. This is because a plaintext block can be recovered from two adjacent blocks of ciphertext. As a consequence, decryption can be parallelized. Note that a one-bit change to the ciphertext causes complete corruption of the corresponding block of plaintext, and inverts the corresponding bit in the following block of plaintext, but the rest of the blocks remain intact.

这就是为什么未经身份验证的加密(例如 here)不是一个好主意的原因之一。

另一方面,在加密期间更改 IV 会导致完全不同的密文,因为第一个块中的更改会传播到所有后续块。

免责声明:我不是加密专家,所以请验证我的想法。