【问题标题】:Encrypted text to passed as id in the url in asp.net mvc在 asp.net mvc 的 url 中作为 id 传递的加密文本
【发布时间】:2013-10-03 16:26:26
【问题描述】:

我正在通过在注册时向用户发送电子邮件来实施电子邮件验证。成功注册后,一封带有“http://mydomain.com/Account/Activate/EncryptedKeyID”链接的邮件。有时我得到 '/' 或无法传递给 url 的特殊字符。所以,我使用 HttpUtility.UrlEncode 进行编码。但这无济于事。当我单击电子邮件时,由于“http://mydomain.com/Account/Activate/JLU/YmtRdRAFmBdqhR7tnA==”中有多余的斜杠,它会给出 IIS 错误。我使用 Rijndael/AES 进行加密和解密。

我的问题是: 我应该使用另一种加密方法吗? 有没有其他选择?

提前感谢您的时间和帮助

【问题讨论】:

    标签: asp.net-mvc url encryption


    【解决方案1】:

    经过挖掘,我发现 HttpUtility.UrlEncode 不适用于我的情况,我必须使用 HttpServerUtility.UrlTokenEncode 因为它对 url 更安全。它不包含任何具有潜在危险的字符“+”和“/”字符,而是带有“-”和“_”。对于我的情况,我使用var ativationLink=HttpServerUtility.UrlTokenEncode(Convert.FromBase64String(Rij.Encrypt(param))); 作为添加电子邮件的链接。

    并检索我使用的原始参数

     var param= Rij.Decrypt(Convert.ToBase64String(HttpServerUtility.UrlTokenDecode(ActivationKey)));
    

    【讨论】:

      猜你喜欢
      • 2010-10-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-05-04
      • 2011-05-26
      • 1970-01-01
      • 1970-01-01
      • 2016-01-28
      相关资源
      最近更新 更多