Header add

In this article we disccus how to Encrypt and Decrypt Username or Password stored in database in ASP.Net using C#. 

The Username or Password will be first encrypted using AES Symmetric key (Same key) algorithm and then will be stored in the database. The Decryption will be done by fetching the encrypted Username or Password from Database and then decrypting it using the same key that was used for encryption.

Create the database table like below;

 HTML mark up design

➤ Encrypting and storing the Password in Database Table

When the Submit Button is clicked, the Username and Password will be inserted into the SQL Server database table.The Username is inserted directly but the Password is first encrypted using the Encrypt function and then it is inserted.

Add the connection string accordingly in the Web.config file.

➤ Displaying the Username and password Encrypted and Decrypted

Inside the Page Load event, the GridView control is populated with the records from the Users table.
Then inside the OnRowDataBound event handler, the encrypted Password is fetched and decrypted using the Decrypt function.

➤ AES Algorithm Encryption and Decryption functions

Create a static class of AES encryption and decryption method like below;

Finally, Run the application and see the output like below;


</> Source Code in Github.com/CoreProgramm/

  In this tutorial we discussed how to Encrypt and Decrypt Username or Password stored in database in ASP.Net using C#. If have any question related to this topic then give your feedback.

Post a Comment

Previous Post Next Post