【发布时间】:2016-11-25 20:29:25
【问题描述】:
我在以下代码中注意到以下奇怪的行为,如果我在对象初始化程序中设置 Key,它会生成一个随机密钥并且不会设置我的密钥。这是一个故障吗?
var algorithm = new RijndaelManaged
{
Mode = CipherMode.CBC,
Key = keyBytes, //if i set the keyBytes here
KeySize = _keySize,
IV = Encoding.ASCII.GetBytes(_initVector),
BlockSize = 128,
Padding = PaddingMode.Zeros
}; // Set encryption mode to Cipher Block Chaining
bool wtf= algorithm.Key.AreEqual(keyBytes);
if (!wtf) // <!-- the Key is not the same here
{
algorithm.Key = keyBytes; // so i end up having to set it again here so that i can decrypt properly
}
【问题讨论】:
标签: c# rijndaelmanaged