【发布时间】:2011-02-24 22:13:46
【问题描述】:
正如标题所说,我得到:
Base-64 字符的长度无效 数组。
我在这里读到过这个问题,似乎 如果 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);
}
Encrypt 方法如下所示:
public static string Encrypt(string clearText, string Password)
{
byte[] clearBytes = System.Text.Encoding.Unicode.GetBytes(clearText);
PasswordDeriveBytes pdb = new PasswordDeriveBytes(Password, new byte[] { 0x49, 0x76, 0x61, 0x6e, 0x20, 0x4d, 0x65, 0x64, 0x76, 0x65, 0x64, 0x65, 0x76 });
byte[] encryptedData = Encrypt(clearBytes, pdb.GetBytes(32), pdb.GetBytes(16));
return Convert.ToBase64String(encryptedData);
}
这是 HTML 在 hotmail 中的样子:
请点击以下链接或 将其粘贴到浏览器中以验证您的 电子邮件帐户。
http://localhost:1563/Accounts/VerifyEmail.aspx?a=YOHY57xYRENEOu3H+FGq1Rf09AZAI56EPjfwuK8XWKg=
在接收端,VerifyEmail.aspx.cs页面有一行:
string username = Cryptography.Decrypt(_webContext.UserNameToVerify, "verify");
这是 UserNameToVerify 的 getter:
public string UserNameToVerify
{
get
{
return GetQueryStringValue("a").ToString();
}
}
这里是 GetQueryStringValue 方法:
private static string GetQueryStringValue(string key)
{
return HttpContext.Current.Request.QueryString.Get(key);
}
解密方法如下:
public static string Decrypt(string cipherText, string password)
{
**// THE ERROR IS THROWN HERE!!**
byte[] cipherBytes = Convert.FromBase64String(cipherText);
能否通过代码修复来纠正此错误,或者我必须将 ViewState 存储在数据库中吗?
【问题讨论】:
标签: c# asp.net viewstate base64