I've noticed the following strange behaviour in the following code, if I set the Key in an object initializer it generates a random key and doesn't set my key. Is this a glitch?
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
}