Resolved: 3DES Decryption gives different results at each iteration


Playing around with 3DES encryptions and decryptions, I use this fairly simple and standard code. However, I get different decryptionData value as output everytime I run this function.
Can someone point me what’s wrong?
PS: These are just random keys and data, no sensitive stuff.


For the TripleDESCryptoServiceProvider.KeySize property applies:

Changing the KeySize value resets the key and generates a new random key. This happens whenever the KeySize property setter is invoked (including when it’s assigned the same value).

Therefore, in the posted code, the originally set key is overwritten by a randomly generated key, which is why a different result is generated each time. Fix: Remove the explicit KeySize call. This is not necessary, because the key size is implicitly set with the key.
Note that Triple DES is outdated and ECB is insecure.

If you have better answer, please add a comment about this, thank you!