在某些情况下,我通过 (decryption) 得到以下异常,我无法准确识别原因:



我的代码:

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());

抛出异常的确切行是:
 Byte[] byteArray = Convert.FromBase64String(text);

我以为我通过在加密和解密操作前后进行编码和解码来解决这个问题。但是有些值仍然抛出这个异常。

注意:我注意到一些奇怪的行为:
作为发送到我的邮件的查询字符串的 id 是:n%2bsJJPXprU4%3d,它可以正常工作..

和有问题的用户发送的 url 包含 3Dn%2bsJJPXprU4%3d
这是浏览器的问题吗??!!

最佳答案

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

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

10-07 19:17
查看更多