Invalid length for a Base-64 char array while decryption

asp.net, base64, c#, encryption, exception

Solution

Decoding the querystring values is done already when it's parsed into the Request. try without 'HttpUtility.UrlDecode'

public static string decodeSTROnUrl(string thisDecode)
    {
        return Decrypt(thisDecode);
    }

Problem

I get the following exception in some cases through (decryption) , and i can't recognize exactly the reason : Invalid length for a Base-64 char array My Code : ``` public static string encodeSTROnUrl(string thisEncode) { if (null == thisEncode) return string.Empty; return HttpUtility.UrlEncode(Encrypt(thisEncode)); } // string thisDecode = "3Dn%2bsJJPXprU4%3d"; //this is the value which cause the exception. public static string decodeSTROnUrl(string thisDecode) { return Decrypt(HttpUtility.UrlDecode(thisDecode)); } QueryStringEncryption.Cryptography.decodeSTROnUrl(Request.QueryString["val"].ToString()); ``` The exact line which throw the exception is : ``` Byte[] byteArray = Convert.FromBase64String(text); ``` I thought i fix this problem by encoding and decoding before and after the encryption and the decryption operation.but some values still throw this exception . Note: i note some strange behavior : the id as a query string sent to my mail is : `n%2bsJJPXprU4%3d` and it works without exceptions .. and the user who has the problem the sent url contains `3Dn%2bsJJPXprU4%3d` is this a browser problem ??!!

Original source

Related problems