简体   繁体   English

如何加密 id 查询字符串参数

[英]How can I encrypt the id querystring parameter

I need to send "@id" parameter with encrypted (on browser search bar) then decrypted the id to get id's values from Edit view.How can I use AES cryptography.我需要发送带有加密的“@id”参数(在浏览器搜索栏上),然后解密 id 以从编辑视图中获取 id 的值。如何使用 AES 加密。

public ActionResult Edit(int? id)
{
    return view(model);
}

You can't encrypt and decrypt a parameter in a query string param in a URL.您无法加密和解密 URL 中查询字符串参数中的参数。 If you want to pass parameters between a client browser and host system, the parameter has to be buried in the content of the messaging between the host and client while the entire messaging is encrypted via HTTPS.如果要在客户端浏览器和主机系统之间传递参数,则必须将参数隐藏在主机和客户端之间的消息传递内容中,同时整个消息传递通过 HTTPS 进行加密。

You can do it by this steps :您可以通过以下步骤完成:

Step 1: Create a new class in your project and copy paste the code from This Link .第 1 步:在您的项目中创建一个新类并复制粘贴This Link 中的代码。

Step 2: Build the project now第 2 步:立即构建项目

step 3:第 3 步:

Put the MyExtension namespace on top of your page (view)MyExtension命名空间放在页面顶部(视图)

@Html.EncodedActionLink(item.Name, "YourActionName", "YourControllerName", new { id = item.ID }, null)

Step 4:第四步:

[EncryptedActionParameter]
public ActionResult Edit(int? id)
{
    return view(model);
}

Edited : After I did above steps I found a problem in decryption and I changed it.So you need to change byte[] IV = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 };编辑:在我做了上面的步骤后,我发现解密有问题,我改变了它。所以你需要改变byte[] IV = { 2, 4, 6, 8, 10, 12, 14, 16, 18, 20 }; to byte[] IV = { 55, 34, 87, 64, 87, 195, 54, 21 };byte[] IV = { 55, 34, 87, 64, 87, 195, 54, 21 }; in Decrypt and Encrypt methods in MyExtensions class.MyExtensions类中的DecryptEncrypt方法中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在asp.net中保护/加密查询字符串? - How can you secure/encrypt your querystring in asp.net? 我可以使用Request.Url.Query自动删除querystring上的参数吗? - Can I automatically remove a parameter on querystring with Request.Url.Query? 我可以使用NavigationContext.QueryString设置参数吗? (Windows Phone) - Can I set parameter using NavigationContext.QueryString? (Windows Phone) 我怎样才能将查询字符串传递给aspx - how can i pass the querystring into aspx 在查询字符串上找不到参数 - Can't find parameter on querystring 如何将参数从查询字符串传递到Autofac中的组件注册? - How do I pass a parameter from a querystring to a component registration in Autofac? 如何检查 QueryString 是否没有参数 - How to Check If QueryString has no parameter 如何从我的视图运行方法,并将其返回到发送页面,该页面需要基于类别ID的查询字符串,因此无法发送? - How can I run a method from my view, and have it return to the sending page, which requires a Category ID based querystring it's not sent? 如何在C#中加密字符串? - How I can encrypt a string in c #? 加载视图后,如何删除(或隐藏)查询字符串? - How can I remove (or hide) the querystring after a View loads?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM