簡體   English   中英

解密時Base-64 char數組的長度無效

[英]Invalid length for a Base-64 char array while decryption

在某些情況下,我通過(解密)獲得以下異常,我無法確切地知道原因:

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

拋出異常的確切行是:

 Byte[] byteArray = Convert.FromBase64String(text);

我認為我通過加密和解密操作之前和之后的編碼和解碼來解決這個問題。但是一些值仍然會引發此異常。


注意:我注意到一些奇怪的行為:作為查詢字符串的id發送到我的郵件是: n%2bsJJPXprU4%3d它沒有例外..

並且有問題的用戶發送的網址包含3Dn%2bsJJPXprU4%3d

這是一個瀏覽器問題?? !!

解析查詢字符串值在解析為請求時已經完成。 嘗試沒有'HttpUtility.UrlDecode'

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

64位編碼在字符串中存在空格問題。 嘗試在加密后添加以下內容

sEncryptedString = sEncryptedString.Replace(' ', '+');

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM