Encrypt and Decrypt Connection String in Asp.Net

Encrypt and Decrypt Connection String in Asp.Net

In this post we will discuss how we can Encrypt and Decrypt Connection String in Asp.Net, or Encrypt and Decrypt Asp.Net Connection. To accomplish this we have to follow one simple step provided itself in Visual Studio.

1. Go to Start Menu.

2. Start Menu > Programs > Visual Studio 2013 or Microsoft Visual Studio 2010 > Visual Studio Tools > Visual Studio Command Prompt.

3. Run Below mentioned Command to encrypt the ConnectionString.

aspnet_regiis.exe -pef "connectionStrings" "C:\Demo Live V 1.3"

4. Run Below mentioned Command to decrypt the ConnectionString.

aspnet_regiis.exe -pdf "connectionStrings" "C:\Demo Live V 1.3"

Parameters:
Action – It notifies the action to be performed. In order to perform Encryption, the parameter value is -pef.For Decryption parameter value is -pdf.
Section Name – The name of the section of the Web.Config file to be encrypted. For this case, the value will be connectionStrings.
Path of the folder – Here we need to specify the path of the folder containing the Web.Config file.

Note: Encryption done on one machine will not decrypted on another machine. For that you have to use Using RSA with a User-level Key Container. For more info please read here: https://msdn.microsoft.com/en-us/library/ff650304.aspx