Header add

In this article we discuss how to Encrypt a razor filed in JavaScript and Decrypt in C# With AES Algorithm in ASP.Net MVC. You know that in web application the security is a major part while we develop a application.

Suppose in a login page, when we post the username and password it shouldn't be in a raw text, the hacker may read the raw text any intercept like (Burp Suite etc.) and read the data. To Secure this we need to encrpt the data in Razor page using AES algorithm using JavaScript and then Decrypt it in C# using same algorithm.

What is AES Algorithm ?

Advanced Encryption Standard (AES) is a symmetric encryption algorithm.The algorithm was developed by two Belgian cryptographers, Joan Daemen and Vincent Rijmen.

The features of AES are as follows −
  • Symmetric key symmetric block cipher
  • 128-bit data, 128/192/256-bit keys
  • Stronger and faster than Triple-DES
  • Provide full specification and design details
  • Software implementable in C and Java
Let's do create a ASP .NET MVC application and in the login page we are going to use the encryption and Decryption method.

   File ➜ New Project ➜ Choose ASP .NET MVC application
   Create a login model Class inside the Models Folder.

  Download and add the aes.js in the script folder (The aes.js are shared in Github source code link)
  As we are consider the ASP .NET MVC template then there is already have the HomeController.cs and in Index() we need to add our Login page html code. The complete set of HTML code of index.cshtml is



Then we need to add the AES encryption method in C# code like below;

And we need to add the Post method where we decrypt the username and password like below;

When you run the application you can see the output like below;



You can see using below those steps we should do the encryption in razor pages and decryption in C# page.

</> Source Code in Github.com/CoreProgramm/
  In this tutorial we discussed Encrypt in JavaScript and Decrypt in C# With AES Algorithm in ASP.Net MVC. If have any question related to this topic then give your feedback.

Post a Comment

Previous Post Next Post