相关疑难解决方法(0)

Base-64 char数组的长度无效

正如标题所说,我得到:

Base-64 char数组的长度无效.

我已经在这里阅读了这个问题,似乎建议将ViewState存储在SQL中,如果它很大的话.我正在使用一个带有大量数据收集的向导,所以我的ViewState很可能很大.但是,在我转向"存储在数据库"解决方案之前,也许有人可以看看并告诉我是否有其他选择?

我使用以下方法构建了用于传递的电子邮件:

public void SendEmailAddressVerificationEmail(string userName, string to)
{
    string msg = "Please click on the link below or paste it into a browser to verify your email account.<BR><BR>" +
                    "<a href=\"" + _configuration.RootURL + "Accounts/VerifyEmail.aspx?a=" +
                    userName.Encrypt("verify") + "\">" +
                    _configuration.RootURL + "Accounts/VerifyEmail.aspx?a=" +
                    userName.Encrypt("verify") + "</a>";

    SendEmail(to, "", "", "Account created! Email verification required.", msg);
}
Run Code Online (Sandbox Code Playgroud)

Encrypt方法如下所示:

public static string Encrypt(string clearText, string Password)
{

    byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);

    PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new …
Run Code Online (Sandbox Code Playgroud)

c# asp.net viewstate base64

80
推荐指数
4
解决办法
20万
查看次数

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

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

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

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

c# asp.net encryption base64 exception

4
推荐指数
1
解决办法
7774
查看次数

标签 统计

asp.net ×2

base64 ×2

c# ×2

encryption ×1

exception ×1

viewstate ×1