为了账号安全,请及时绑定邮箱和手机立即绑定

Base-64 char数组的长度无效

Base-64 char数组的长度无效

鸿蒙传说 2019-10-17 14:55:16
如标题所示,我得到: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);}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);}这是Hotmail中的HTML外观:请单击下面的链接或将其粘贴到浏览器中以验证您的电子邮件帐户。http:// localhost:1563 / Accounts / VerifyEmail.aspx?a = YOHY57xYRENEOu3H + FGq1Rf09AZAI56EPjfwuK8XWKg =在接收端,VerifyEmail.aspx.cs页面的行如下: string username = Cryptography.Decrypt(_webContext.UserNameToVerify, "verify");这是UserNameToVerify的获取方法: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存储在数据库中?
查看完整描述

3 回答

  • 3 回答
  • 0 关注
  • 643 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信