I am using the AES enscryption to decrypt the value
In C# 4.0
the code is written like this to decrypt the value
encodedIdentityData contain the Encrypted value
//string decodedIdentityData = Encoding.Unicode.GetString(MachineKey.Decode(encodedIdentityData, MachineKeyProtection.All))+",";
i am having C#3.5 framework at my producation i cannot be updating it framework 4.0
so i have rewritten the code to decrypt the value inc# 3.5 like this
public static string Decrypt(string encryptedTicket)
{
return FormsAuthentication.Decrypt(encryptedTicket).UserData;
}
when when i decrypt herein c# 3.5 i am getting an exception
"Length of the data to decrypt is invalid."
at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
prince23
Member
18 Points
91 Posts
decrypt not working fine using AES getting (Length of the data to decrypt is invalid)
Jan 06, 2013 03:21 AM|LINK
Hi
I am using the AES enscryption to decrypt the value
In C# 4.0
the code is written like this to decrypt the value
encodedIdentityData contain the Encrypted value
//string decodedIdentityData = Encoding.Unicode.GetString(MachineKey.Decode(encodedIdentityData, MachineKeyProtection.All))+",";
i am having C#3.5 framework at my producation i cannot be updating it framework 4.0
so i have rewritten the code to decrypt the value inc# 3.5 like this
string strENC=Encrypt(encodedIdentityData);
public static string Encrypt(string cookieValue)
{
return FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1,
string.Empty,
DateTime.Now,
DateTime.Now.AddMinutes(30),
true,
cookieValue));
}
public static string Decrypt(string encryptedTicket)
{
return FormsAuthentication.Decrypt(encryptedTicket).UserData;
}
when when i decrypt herein c# 3.5 i am getting an exception
"Length of the data to decrypt is invalid."
at System.Security.Cryptography.RijndaelManagedTransform.TransformFinalBlock(Byte[] inputBuffer, Int32 inputOffset, Int32 inputCount)
at System.Security.Cryptography.CryptoStream.FlushFinalBlock()
at System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, IVType ivType, Boolean useValidationSymAlgo)
at System.Web.Security.FormsAuthentication.Decrypt(String encryptedTicket)
machine key what is used to decrypt it
<machineKey validationKey="0C4929BE691B98F63B94F2A7AA9CA5E1F430D6FFFA91FBEDAEC1D2DDAAC2127EB055DB857F5550ABC6EE8451D9AE3C13AFB78328C5BDE83249A94EA66400453B" decryptionKey="668B59FD4684EA13EACEAA833F2EEEABBECF2D066199F5C2D3652E224A82C265" validation="SHA1" decryption="AES" />
any help on this would be great
Thanks
KUmar
BrockAllen
All-Star
27512 Points
4895 Posts
MVP
Re: decrypt not working fine using AES getting (Length of the data to decrypt is invalid)
Jan 06, 2013 03:27 AM|LINK
Write this code:
string strENC=Encrypt(encodedIdentityData);
string strPlain = Decrypt(strENC);
and see if you have the same exception.
DevelopMentor | http://www.develop.com
thinktecture | http://www.thinktecture.com/
prince23
Member
18 Points
91 Posts
Re: decrypt not working fine using AES getting (Length of the data to decrypt is invalid)
Jan 07, 2013 06:42 AM|LINK
Thanks for te reply
Decrytedvalue=d239f325-0e7e-4dcb-8d37-86fb95814c80;c.kumar@gmail.com,1,.india.com,931
EncryptedValue="FF8B1FEF0B3269D67D178CB56705EB5D9E7272FAA3E155AAB13C6DF4EE423522AFCFFF1BF6299BE989E96C906C24088FB3A9ABB7ADCAF15C12ED4801F70960DFA471710B2F137FA456C76504B97EB3B938F9C1D52B77D57F2F4811C16403544D31A60D69A25171A996DDD36C1F64A89B2B58D391F9B9DF0A212C280E6E069EB0D06EDA2DCC7972F2D8DAD1F667C52E103E223890335F6C770F6C0A0D3572778DD655BEF390B6C94C5BA931FFD8845458177A4219DB90768749B83FDA57CC89A4CB2D54AE7A7E5735C3AC67E2AFED26FFDB6AE92F5EEF67DCE46727EE796F438C8BD96EFA60C2EDB070408A99119A2E3E206967E2"
when i pass my EncryptedValue to get decryted value it throws :
exception:
Length of the data to decrypt is invalid.
Angie xu - M...
All-Star
18446 Points
1560 Posts
Microsoft
Re: decrypt not working fine using AES getting (Length of the data to decrypt is invalid)
Jan 11, 2013 05:39 AM|LINK
Hi KUmar
There are something wrong with the parameter in FormsAuthenticationTicket or FormsAuthentication.Decrypt method according to error message.
you could refer the FormsAuthenticationTicket Class and FormsAuthentication.Decrypt method below, and check whether you use them properly,
FormsAuthenticationTicket Class
FormsAuthentication.Decrypt Method
Understanding the Forms Authentication Ticket and Cookie http://support.microsoft.com/kb/910443
hope it helps you,
Kind regards
Feedback to us
Develop and promote your apps in Windows Store