解密时Base-64 char数组的长度无效

Any*_*are 4 c# asp.net encryption base64 exception

在某些情况下,我通过(解密)获得以下异常,我无法确切地知道原因:

Base-64 char数组的长度无效

我的代码:

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());
Run Code Online (Sandbox Code Playgroud)

抛出异常的确切行是:

 Byte[] byteArray = Convert.FromBase64String(text);
Run Code Online (Sandbox Code Playgroud)

我认为我通过加密和解密操作之前和之后的编码和解码来解决这个问题.但是一些值仍然会引发此异常.


注意:我注意到一些奇怪的行为:作为发送到我的邮件的查询字符串的id是:n%2bsJJPXprU4%3d并且它没有例外地工作..

以及发送网址包含问题的用户 3Dn%2bsJJPXprU4%3d

这是一个浏览器问题?? !!

Dam*_*ith 8

解析查询字符串值在解析为请求时已经完成.尝试没有'HttpUtility.UrlDecode'

public static string decodeSTROnUrl(string thisDecode)
    {
        return Decrypt(thisDecode);
    }
Run Code Online (Sandbox Code Playgroud)