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.
public ActionResult Edit(int? id)
{
return view(model);
}
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.
public ActionResult Edit(int? id)
{
return view(model);
}
You can't encrypt and decrypt a parameter in a query string param in a 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.
You can do it by this steps :
Step 1: Create a new class in your project and copy paste the code from This Link.
Step 2: Build the project now
step 3:
Put the MyExtension
namespace on top of your page (view)
@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 };
to byte[] IV = { 55, 34, 87, 64, 87, 195, 54, 21 };
in Decrypt
and Encrypt
methods in MyExtensions
class.