In the world of web development, safeguarding sensitive information is a paramount concern. One critical area to address is securing database connections. In this tutorial, we’ll delve into the process of encrypting your database connection strings within the web.config file using .NET technologies.

The easiest method to encrypt the <connectionStrings> section is by using the “aspnet_regiis” command-line tool.

Step 1. Open Command Prompt

Step 2. Navigate to your .NET Framework folder using the following statement. Keep in mind that the directory may vary depending on your installed version:

cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

Step 3. Encrypt the <connectionString> section using the command below. For instance, if your website’s web.config is located at “c:\path\YourWebsite”:

ASPNET_REGIIS -pef "connectionStrings" "c:\path\YourWebsite"


Step 4. To decrypt the section, simply change -pef to -pdf.

ASPNET_REGIIS -pdf "connectionStrings" "c:\path\YourWebsite

Here is example of your encrypted web.config file:

If you have any other sensitive section that needs encryption, simply replace <connectionString> with your section name, for example, <databaseConnection>.

By tajuzzaman

📍Kelabu Ventures 📍Aurora Cloud Works Sdn Bhd . A magician who writes code for computer, web, ios & android app . Servant of The One, Soldier of life