Click here to Skip to main content
11,721,385 members (79,811 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#4.0 .NET4
When I am trying to dercypt my encrypted text I am getting the following error
"Bad Data:Cryptographic exception Was unhandled"

I am getting the error at following line of code
byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);

this is my code for decrption

public string decrypt(string code, string Key)
           bool useHashing = true;
           byte[] keyArray;
           byte[] toEncryptArray = Convert.FromBase64String(code);
           //System.Configuration.AppSettingsReader settingsReader = new AppSettingsReader();
           //Get your key from config file to open the lock!
           //string key = (string)settingsReader.GetValue("SecurityKey", typeof(String));
           string key = Key;
           if (useHashing)
               MD5CryptoServiceProvider hashmd5 = new MD5CryptoServiceProvider();
               keyArray = hashmd5.ComputeHash(UTF8Encoding.UTF8.GetBytes(key));
               keyArray = UTF8Encoding.UTF8.GetBytes(key);
           TripleDESCryptoServiceProvider tdes = new TripleDESCryptoServiceProvider();
           tdes.Key = keyArray;
           tdes.Mode = CipherMode.ECB;
           tdes.Padding = PaddingMode.PKCS7;
           ICryptoTransform cTransform = tdes.CreateDecryptor();
           byte[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);
           return UTF8Encoding.UTF8.GetString(resultArray);
I am not getting what is the probles as this code was working properly before.plz help. thanks in advance

[edit]Code block added - OriginalGriff[/edit]
Posted 26-Oct-12 2:07am
Edited 26-Oct-12 2:10am
(no name)1.4M
OriginalGriff at 26-Oct-12 8:08am
"this code was working properly before."
Before what?
I.e. What has changed since it last worked. This is probably relevant to your question...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 380
1 OriginalGriff 254
2 Mika Wendelius 170
3 cyycoish 70
4 ppolymorphe 66
0 Sergey Alexandrovich Kryukov 2,249
1 OriginalGriff 1,024
2 F-ES Sitecore 690
3 Maciej Los 619
4 Richard MacCutchan 580

Advertise | Privacy | Mobile
Web01 | 2.8.150901.1 | Last Updated 26 Oct 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100