[英]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
类中的Decrypt
和Encrypt
方法中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.