Why does set key not do anything in AES/SymmetricAlgorithm?

Posted by acidzombie24 on Stack Overflow See other posts from Stack Overflow or by acidzombie24
Published on 2010-06-14T22:30:10Z Indexed on 2010/06/14 22:32 UTC
Read the original article Hit count: 140

This MESSED ME UP hard. I thought i was setting the key but i was not. No exceptions, nothing happen except bad results. Why is there a setter if everything is ignored and no exceptions are thrown when i attempt to write? What is the point of the setter on the Keys property?

When i do the below Key value are not changed. After an hour when i realize what was happening i wrote the loop to verify. I also tried aes.Key[0] = val; var b = val == aes.Key[0]; (and messed with it in immediate mode).

Why does it have this behavior?

Array.Copy(myKey, aes.Key, aes.Key.Length);

int i = 0;
foreach (var v in aes.Key)
{
    var b = myKey[i++] == v;
    if (!b)
        b = b;
}

© Stack Overflow or respective owner

Related posts about .NET

Related posts about properties