Sudantha
Sudantha

Reputation: 16204

TripleDES Decryption in C#

TripleDES = new TripleDESCryptoServiceProvider();
this.GenerateKey(); //Generate Key ..
TripleDES.Mode = CipherMode.CBC;
TripleDES.Padding = PaddingMode.PKCS7;



byte[] cipher = new byte[0];
ICryptoTransform ict = TripleDES.CreateEncryptor();
cipher = ict.TransformFinalBlock(data, 0, data.Length); 

Hi when i decypt the message using the same instance of the TripleDES = new TripleDESCryptoServiceProvider(); works properly but when i try to dcrypt using a new instance it says "Bad Data"

Upvotes: 0

Views: 830

Answers (1)

Kokayca
Kokayca

Reputation: 176

I believe you are generating a new key on each run. Try giving a static key instead of using this.GenerateKey();.

Upvotes: 4

Related Questions