Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Aug 25, 2008 03:44 PM by Ammi
Aug 22, 2008 03:27 PM|LINK
I am encrypting and decrypting query string. If i pass a long query string it gives error
'Invalid length for a Base-64 char array.' while decrypting . The encryption works fine. If i pass a short string the decryption works fine. Is there any solution fot this?
my code for decrypting is:
public string Decrypt(string stringToDecrypt)
byte toDecrypt = System.Convert.FromBase64String(stringToDecrypt);
byte encryptionKey = System.Text.ASCIIEncoding.ASCII.GetBytes(key);
byte iVector = System.Text.ASCIIEncoding.ASCII.GetBytes(initVector);
MemoryStream memoryStream = new MemoryStream(toDecrypt.Length);
DESCryptoServiceProvider desCryptoServiceProvider = new DESCryptoServiceProvider();
CryptoStream cryptoStream = new CryptoStream(memoryStream, desCryptoServiceProvider.CreateDecryptor(encryptionKey, iVector), CryptoStreamMode.Read);
memoryStream.Write(toDecrypt, 0, toDecrypt.Length);
memoryStream.Position = 0;
string decrypted = new StreamReader(cryptoStream).ReadToEnd();
Aug 22, 2008 03:33 PM|LINK
How long is the string that you are trying to decrypt? Can you check that it has all the characters that you expect it to? Note that Base64 encoding is not the same as URL encoding and that if it's been on the query string, there may be issues with it. You
will need to URL encode it as well as Base64 encode it.
Aug 22, 2008 04:01 PM|LINK
The string i pass ranges from 20 characters to 80 characters length and it contains spaces and '&'. And how do i URL encode it?
Aug 22, 2008 04:06 PM|LINK
And obviously the equivalent for decoding potentially.
Aug 22, 2008 06:16 PM|LINK
It is not working. I used URL encode first and encryption. Same thing happens. Short strings work but nothe long strings. Any idea?
Aug 25, 2008 03:44 PM|LINK
My problem is solved. I used both URL encode as well as encryption. This time i got it right.
Thanks a lot.