Request.Querystring 从加密文本中删除字符
在我的应用程序中,我获取用户的电子邮件地址,对其进行加密、URLEncode,然后将其传递到查询字符串中。
email = Server.UrlEncode(aes.Encrypt(email));
登陆页面执行 Request.Querystring["email"]、UrlDecodes,然后解密。
string email = Server.UrlDecode(Request.QueryString["eId"]);
string decemail = aes.Decrypt(email);
return decemail;
当“+”字符被删除时,发生了非常奇怪的行为,因此解密失败。
我尝试删除 UrlDecode,但这并没有解决问题。
解决问题的方法是这样做:
string email = Request.QueryString["eId"].ToString();
string decemail = aes.Decrypt(email);
return decemail;
摆脱 UrlDecode,并在查询字符串上调用 ToString()。
有谁知道为什么会发生这种情况? Request.QueryString默认调用urlDecode吗?我认为不会。
另外,为什么在这种情况下执行 .ToString() 会起作用?
In my application I take a user's e-mail address, encrypt it, and URLEncode it, and pass it along into a QueryString.
email = Server.UrlEncode(aes.Encrypt(email));
The landing page does a Request.Querystring["email"], UrlDecodes it, and then decrypts it.
string email = Server.UrlDecode(Request.QueryString["eId"]);
string decemail = aes.Decrypt(email);
return decemail;
Very strange behavior was happening where a "+" character was being removed and therefore the decryption was failing.
I attempted to remove the UrlDecode, but that didn't solve the problem.
What solved the problem was doing this:
string email = Request.QueryString["eId"].ToString();
string decemail = aes.Decrypt(email);
return decemail;
Getting rid of UrlDecode, and calling a ToString() on the querystring.
Does anyone know why this would happen? Does Request.QueryString call urlDecode by default? I don't think it does.
Also, why would doing the .ToString() work in this instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,正确。 Request.QueryString实际上返回已经被url解码的字符串。
资料来源:
Yep Correct. Request.QueryString actually returns string that has already been url decoded.
Sources: