Question:
Playing around with 3DES encryptions and decryptions, I use this fairly simple and standard code. However, I get differentdecryptionData
value as output everytime I run this function.Can someone point me what’s wrong?
Answer:
For theTripleDESCryptoServiceProvider.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!
Source: Stackoverflow.com
Leave a Review