|
-
Feb 26th, 2009, 12:20 PM
#1
Thread Starter
Frenzied Member
invalid length for a base 64 char array
Hi I have a code below, but everytime, my "text" throwing an error invalid length for a base 64 char array, and I don't know how to fix this.
Code:
try
{
key = Encoding.UTF8.GetBytes(stringKey.Substring(0, 8));
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
Byte[] byteArray = Convert.FromBase64String(text);
MemoryStream memoryStream = new MemoryStream();
CryptoStream cryptoStream = new CryptoStream(memoryStream,
des.CreateDecryptor(key, IV), CryptoStreamMode.Write);
cryptoStream.Write(byteArray, 0, byteArray.Length);
cryptoStream.FlushFinalBlock();
return Encoding.UTF8.GetString(memoryStream.ToArray());
}
catch (Exception ex)
{
// Handle Exception Here
}
return string.Empty;
-
Feb 26th, 2009, 12:45 PM
#2
Thread Starter
Frenzied Member
Re: invalid length for a base 64 char array
Turned out there's a "+" sign in my string, but how to get rid of it? If I put any other characters, it will screw up my string though.
-
Feb 27th, 2009, 03:31 AM
#3
Re: invalid length for a base 64 char array
The proper way to get rid of it is to tackle it at its source. If it's coming in from a database then figure out what's putting it there and get that application to do it right.
The improper way is to perform a .Replace(), replacing the + with an empty string, but that doesn't guarantee future problems in the base64 string, since other characters may get introduced in there.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|