Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys,

can u suggest me how to solved this error.

Error: "Invalid character in a Base-64 string".

I am sending query string in encoded format and Retrieved it on another page and decode it.Encode and Decode is performed using two methods mentions bellowed.

C#
txtclientcode.Text = Page.Request.Form["clientcode"].ToString();
TextBox1.Text = DecodeTo64UTF8(txtclientcode.Text.ToString());


and methods are

C#
private static string EncodeTo64UTF8(string str)
{

    byte[] toEncode2Bytes = System.Text.Encoding.UTF8.GetBytes(str);

    string sReturnValue = System.Convert.ToBase64String(toEncode2Bytes);

    return sReturnValue;

}

private static string DecodeTo64UTF8(string eValue)
{

   byte[] encodedDataBytes = System.Convert.FromBase64String(eValue);

   string sReturnValue = System.Text.Encoding.UTF8.GetString(encodedDataBytes);

   return sReturnValue;

}


Thanks,
Pinank Kella.
Posted
Updated 19-Jul-12 20:41pm
v2

The error means that your encoded string going in, is broken. It's probably been modified along the way, use the debugger to check the value coming out against what comes out of the encode method.
 
Share this answer
 
Comments
Pratham4950 20-Jul-12 3:07am    
No, when I try on local host then I have getting right value. but when I upload this code that time this error is occurred.
i tried to check your code.
but it's working fine, so i think there is some thing wrong to your another code for sending query string or anything else.

i test it like this and it will working fine.

C#
private static string EncodeTo64UTF8(string str)
        {
            byte[] toEncode2Bytes = System.Text.Encoding.UTF8.GetBytes(str);

            string sReturnValue = System.Convert.ToBase64String(toEncode2Bytes);

            return sReturnValue;
        }

        private static string DecodeTo64UTF8(string eValue)
        {

            byte[] encodedDataBytes = System.Convert.FromBase64String(eValue);

            string sReturnValue = System.Text.Encoding.UTF8.GetString(encodedDataBytes);

            return sReturnValue;

        }

        protected void EncodeDecodTest()
        {
            string str = "id=43&name='xyz'";
            string encode = EncodeTo64UTF8(str);
            string decode = DecodeTo64UTF8(encode);
        }
 
Share this answer
 
I want to decrypt password is "ฆฉ but error Invalid character a Base - 64 bit .how to do decrypt password?
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900