【问题标题】:How to Encrypt/Decrypt query string data如何加密/解密查询字符串数据
【发布时间】:2015-12-26 12:15:09
【问题描述】:

我像这样渲染一个 ActionLink:

@Html.ActionLink(techName, "Details","Home", new { TopicID = item.TechID },null)

我想加密查询字符串,像这样:Home/Details?TopicID=Ek7vP1YwVhc=

我搜索了这个话题和found a piece of code对数据进行加解密:

(new MvcSerializer()).Serialize(<Your data here>, SerializationMode.EncryptedAndSigned)

And then to reverse the process...

(new MvcSerializer()).Deserialize(<Serialized data here>, SerializationMode.EncryptedAndSigned)

如何使用上述方法来加密和解密我的查询字符串?

【问题讨论】:

  • 您复制该代码的post 提到了“MVC Futures”包,并且该问题中的另一个答案确实显示了一种可行的方法。您为什么要寻求帮助以使该问题中得票最低的答案起作用?你试过什么?如果您进一步搜索,您会发现 find 该包中该类的唯一当前支持的重载不再具有 SerializationMode 重载。

标签: c# asp.net-mvc security encryption


【解决方案1】:

您说您希望加密(防止窃听者查看机密数据),但听起来您更像是希望编码 - 格式化数据它可以安全地用作 URI 组件。

你展示的例子看起来像base64:

var base64EncodedText = Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(myText));

另一种方法是 Uri.EscapeString:

var uriEncodedText = Uri.EscapeString(myText);

后者仅更改特殊字符,因此看起来更易于阅读。这可能是优点或缺点。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-21
    相关资源
    最近更新 更多