According to Microsoft's documentation on System.Security.Cryptography.Aes, the key size can simply be changed by setting the KeySize
property.
Does changing the key size automatically generate a new random key of the new key size? The documentation is not clear.
Yes, or no, depending.
Setting
KeySize
makes the object forget the key. If a new one is provided by settingKey
no new key was technically generated. But when the object has no key, but needs one, a new key (of sizeKeySize
) is created and remembered.In general, you should either set
KeySize
(to make a random one) orKey
(which adjustsKeySizeValue
), not both.