How To Do End To End Data Encryption & Decryption in Asp.net Web Form

Data encryption & decryption in ASP.Net web form

Encryption is a process that involves translating your text, documents, images, videos, and other data into gibberish data that cannot be understood by any human or machine. It only becomes readable after decryption which translates the random gibberish data back to its original state. This method can only be performed by someone who knows the exact way to decrypt the data and it often involves a key. Encryption and decryption become very useful when dealing with web applications that are hosted on the client side. As such, the encryption process can help maintain the security of your user’s data.

There are several benefits of encryption and decryption using ASP.Net. These are:

  1. The encryption can be performed in an unlimited number of devices.
  2. It helps ensure the security of your data during remote work and enhances its overall integrity.
  3. A strong encryption key will prevent hacks and other attacks on your web application.
  4. Encryption will also prevent identity theft and help keep you anonymous online.

In this blog, our DEV IT engineers have explained the steps needed to perform encryption and decryption in ASP.Net web forms for your web applications. The steps in doing so are:

1.) First of all, we need the javascript files listed below for the Client side to encrypt the content.

  • System.debug.js
  • System.IO.debug.js
  • System.Text.debug.js
  • System.Convert.debug.js
  • System.BitConverter.debug.js
  • System.IO.BinaryReader.debug.js
  • System.BigInt.debug.js
  • System.Security.Cryptography.SHA1.debug.js
  • System.Security.Cryptography.debug.js
  • System.Security.Cryptography.RSA.debug.js

2.) Next, we’ll need the class mentioned below for server side decryption and other functionality.

3.) Next, you will need two hidden keys filed for public key and for salt string.

4.) Example of Public key and private key used for encryption and decryption

Public key:

<RSAKeyValue><Modulus>{RandomString}Modulus><Exponent>AQAB</Exponent></RSAKeyValue>

Private Key :

<RSAKeyValue><Modulus>{RandomString}</Modulus><Exponent>AQAB</Exponent><P>6iXwohRSA7K3jxR8tA0dTFega1NTF/u/gpNfg3ozJ6Gsj20Udeh14JE+XHTyAFH23O9YN001qzfVDIlJcRkHfmsMe4EMVUlijb3Q+kcF5579v8chb2GMVLlgK67VAZ7E7LCfcDIsd/hmjPtnMiOhDNBDWR03ViGM8P5ypXDKOMM=</P><Q>+yAzMoJ9/k5P9CB5NfnvhTyOWSNhgfTT5GEur09I/f9QM1VL++EpjaKZC5Nce6gjR+OxX7q/5zsZJKqz5i0ZRiS9wMrul0UoqYEc/tG7jr8xDeVsGsIqk+BHHLovUOb6TZjejME9UlwtDwtwniKqTTF54fA6gvCPocUzQ+djtcs=</Q><DP>xJvzAMW7UCujAlubkrxoW5BAvZ4L6dmUJ5qD2yyjA6Y39X8MbS0yvcx35r6z7hzlAwNeuaD1bb3GAW7N4k+4ASj2JEZqCrtCK+61KVK13JWeUIhuxM3OPd4iqMt3RJMCnBR67ITU3jAQPFVlg65zLwU5Z/ymWIZ3iGy/67dXtm0=</DP><DQ>l/lDooSgFP91mWrxj73CuyILj1w/DTOJ7AL4CrXzmWsiMP6krjj0Obe14PB8HoWBXGcqF6HfsuLr82mu11RhoDZp8zucKkV7NyFg18E7PUbtO9iklIj+1WD8CCGQsuglgEJMJGhpYOdRiXJF5B1cbLzNYvNLpaRJd//sZ2Kn0AM=</DQ><InverseQ>wRnIGMNLG2jW1lL5ZA03SjqHrGPnU9zIHt4xJJO0m3oo5WzSm0rkwp60cutgehWH6igNwOHeZLALZ5VSkno+1rO4wixCxL/OdmcXcMRMQUepkU/x3dmnweNiY8aKGv19k7FCl+KgTJvxWNyk0Cm/45lA0Ray+IAddq4a8NF/fKQ=</InverseQ><D>dr55hcwt1BWvg5FT1MHnGtQdyx0Gp5kO30zroJ7e7O8BBTYkAov57KoRG86bLzmvoyaupof/jGIYc5P0oa0vPy2N7IUboKG3ti2Rz/idfjw7GXMl8t64XRGFeyl/GhUWdawG9kwMa6TLGqrehpj+73nzlz2eHB+b4wUJHcP5Okyo1vobvkh7RD3mM8388TLHaNf/h/b5F+Z8nt2lM9ZeUrCD265uBc/TkiZWbMRHIBdxojtltzECgJqui5GZIy90sIUtZvGAVJh3zUpykYllPz4ixmVWj5pnoxyBx0agOo34bCbsO97BtkgW/Td/mCSpWCADUOUHndz35tGzMVTR9Q==</D></RSAKeyValue>

5.) You can save this key to the table and every time the user logins, it will start a new session, and both of these keys will change and store to the table.

Below is the code that changes both keys every time a new login is performed and saves it with respect to the user.

6.) Assign Public Key and Salt Hidden Field variables

7.) How we encrypt the content at the client side.

8.) Here we decrypt that encrypted content at the server side.

Conclusion

By following the steps in the blog, you would have learnt the methods and benefits of encrypting and decrypting your data. Now, you can begin securing yourself and your users with an advanced level of data security in a dangerous world of hackers. If you encounter any issues during the process, then feel free to drop a comment below and we will be sure to get back to you.

The following two tabs change content below.

Dharmesh Chudasama

Sr. Software Developer (.Net) at DEV Information Technology Ltd
Dharmesh Chudasama holds an MCA Master of Computer Application degree in education and works as Sr software developer in .NET technology in DEV IT. Dharmesh has over 8.5 years extensive experience in developing .NET based application and expertise in Basic MVC, C, C#, .NET ,ASP.NET , XM. He is recognized as best leader and team player and skill to easily understand client complex requirements and put in simple manner. Dharmesh loves playing cricket and watching a movie and listening soft music.

Latest posts by Dharmesh Chudasama (see all)

Leave a Reply

Your email address will not be published. Required fields are marked *