How to encrypt and decrypt data in MVC?

2020-05-05 03:12发布

In my MVC application i want to encrypt and decrypt data in data transmission from view to Controller . How to do this in MVC 4 using Razor ?

2条回答
Luminary・发光体
2楼-- · 2020-05-05 03:34

based on this comment: "suppose i am sending an id from my view to my controller and i want to encrypt this id ?"

if you want to encrypt the "id" in a view, in this case you already have the "id" in the view, "id" would be generated in the database or other but not in the client.

In this case, you can encrypt the "id" after put it on the client, and then the controller decrypt only the "id".

Here you have an example that encrypts only the "id", this is done for security so that data is not looking for "id".

In this case you have to encrypt and decrypt the property:

https://stackoverflow.com/a/14774470/138071
http://amitpatelit.com/2011/08/08/url-encryption-in-mvc-application/

In this example (in Spanish) does for all parameters that are received with an underscore (_):

http://geeks.ms/blogs/etomas/archive/2012/07/08/asp-net-mvc-encriptar-routevalues.aspx?utm_source=feedburner&utm_medium=feed&utm_campaign=Feed%3A+BurbujasNetGeeks+%28Burbujas+en+.NET+%28%40geeks.ms%29%29

查看更多
乱世女痞
3楼-- · 2020-05-05 03:37

You don't need to encrypt data from the controller to the view since the view rendering happens in the same computer that the controller is operating.

If you want to encrypt the page that is sent to the user you should use a ssl connection

查看更多
登录 后发表回答