【发布时间】:2019-06-25 14:17:50
【问题描述】:
我需要发送带有加密的“@id”参数(在浏览器搜索栏上)然后解密 id 以从编辑视图中获取 id 的值。如何使用 AES 加密。
public ActionResult Edit(int? id)
{
return view(model);
}
【问题讨论】:
标签: c# asp.net-mvc cryptography
我需要发送带有加密的“@id”参数(在浏览器搜索栏上)然后解密 id 以从编辑视图中获取 id 的值。如何使用 AES 加密。
public ActionResult Edit(int? id)
{
return view(model);
}
【问题讨论】:
标签: c# asp.net-mvc cryptography
您无法加密和解密 URL 中查询字符串参数中的参数。如果要在客户端浏览器和主机系统之间传递参数,则必须将参数隐藏在主机和客户端之间的消息传递内容中,而整个消息传递通过 HTTPS 加密。
【讨论】:
您可以通过以下步骤完成:
第 1 步: 在您的项目中创建一个新类并从This Link 复制粘贴代码。
第 2 步: 立即构建项目
第 3 步:
将 MyExtension 命名空间放在页面顶部(视图)
@Html.EncodedActionLink(item.Name, "YourActionName", "YourControllerName", new { id = item.ID }, null)
第 4 步:
[EncryptedActionParameter]
public ActionResult Edit(int? id)
{
return view(model);
}
已编辑:
完成上述步骤后,发现解密有问题,我将其更改。因此您需要将Decrypt 和MyExtensions 类中的Decrypt 和Encrypt 方法中的byte[] IV = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; 更改为byte[] IV = { 55, 34, 87, 64, 87, 195, 54, 21 };。
【讨论】:
using System.Web.Mvc.Html;