How do I encrypt my web.config file?

Programming, error messages and sample code > ASP.NET
(NOTE THIS IS FOR PREMIUM PLAN or HIGHER ONLY)
 

Please first backup your web.config, and follow the steps below to encrypt it.
 

1)Generate an RSA Key

2)Add the RSA Key into your web.config

3)Encrypt web.config file

4)Export RSA Key

5)Import RSA Key from Control Panel

 

1)Generate RSA Key
Open your dos prompt and run the following command:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pc "dotnetRSAkey_memberID" -exp

Please replace memberID  with your hosting account member ID.  You'll get the following result after running the command:

Creating RSA Key container...
Succeeded!


 

2)Add the following to your web.config

Open your web.config and search for "</configSections>",Add the following to your web.config after the "</configSections>"

 <configProtectedData>
  <providers>
  <add keyContainerName="dotnetRSAkey_memberID"
           useMachineContainer="true"
           description="Uses RsaCryptoServiceProvider to encrypt and decrypt"
           name="CustomProvider"       type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  </providers>
</configProtectedData>

 

3)Encrypt your web.config

Assume your web.config file is in your C:\site1 folder, and you want to encrypt your connectionStrings. Please run the following command in your DOS prompt:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pef "connectionStrings" C:\site1 -prov "CustomProvider"

You should receive the following message:

Encrypting configuration section...
Succeeded!

4)Export RSA Key
Open your DOS prompt and type in the following command:
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -px "dotnetRSAkey_memberID" "C:\dotnetRSAkey_memberID.xml" -pri

You should receive the following message after running the command:

Exporting RSA key to file...
Succeeded!

Your RSA key should be in  C:\dotnetRSAkey_memberID.xml
 

5) Import RSA Key from Control Panel

 

6) Upload the encrypted web.config from C:\site1 to site root.