Caveman's Blog

My commitment to learning.

Posts Tagged ‘aspnet_regiis

Encrypting the Web.Config configurations

with one comment

The web.config is a file that is not accessible to the user of a web application via a browser. The dotnet framework shields this file from all kinds of external intrusion. However someone having access to the physical file can steal sensitive information.

This vulnerability can be overcome by using aspnet_regiis, an in-build ASP.Net tool.  Following these simple steps, sections of the web.config can be encrypted (and/or decrypted) to secure the configuration settings:

Step 1: Encrypt connection Strings in the web.config. This command uses RSAProtectedConfigurationProvider (uses TripleDES and RSA encryption) for encrypting sections of the web.config file. This command has to be executed in a Visual Studio 2005/2008 command prompt window at the location where the web.config resides:

aspnet_regiis -pef connectionStrings .

Step 2: Adding users to the ACL of the key containers using the –pa parameter. Give access to the ASP.NET user:

aspnet_regiis -pa “NetFrameworkConfigurationKey” “ASPNET”

Step 3: Decrypt Connection Strings to clear text

aspnet_regiis -pdf connectionStrings .

The best part is that, the web application code does not have to change one bit after the encryption of web.config file. Following is a before and after view of the Connection Strings section of a web.config file:


  <add name="MembershipConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\LOCALDB.MDF;Integrated Security=True;User Instance=True"
  providerName="System.Data.SqlClient" />


<connectionStrings configProtectionProvider="RsaProtectedConfigurationProvider">
  <EncryptedData Type=""
    <EncryptionMethod Algorithm="" />
    <KeyInfo xmlns="">
      <EncryptedKey xmlns="">
        <EncryptionMethod Algorithm="" />
        <KeyInfo xmlns="">
          <KeyName>Rsa Key</KeyName>

Tip: Here is how to secure appsettings

Encrypt appSettings: aspnet_regiis -pef appSettings .

Decrypt appSettings: aspnet_regiis -pdf appSettings .

1. How To: Encrypt Configuration Sections in ASP.NET 2.0 Using RSA
2. Encrypting configuration files using protected configuration