当我尝试为 TripleDES 加密器创建 IV 初始化向量时出现以下错误。
请看代码示例:
TripleDESCryptoServiceProvider tripDES = new TripleDESCryptoServiceProvider();
byte[] key = Encoding.ASCII.GetBytes("SomeKey132123ABC");
byte[] v4 = key;
byte[] connectionString = Encoding.ASCII.GetBytes("SomeConnectionStringValue");
byte[] encryptedConnectionString = Encoding.ASCII.GetBytes("");
// Read the key and convert it to byte stream
tripDES.Key = key;
tripDES.IV = v4;
这是我从 VS 得到的异常。
指定的初始化向量 (IV) 与该算法的 block 大小不匹配。
我哪里错了?
谢谢
最佳答案
MSDN 明确 states那:
...The size of the IV property must be the same as the BlockSize property.
对于三重 DES,它是 64 位。
关于C# 无法生成初始化向量 IV,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3179304/