Home >

How to protect and encrypt / decrypt .config files in .NET

3. March 2011

Web.config file encryption is simple and people can easily use aspnet_regiis to encrypt / decrypt configuration file but when it comes to app.config based configuration files, aspnet_regiis is overlooked. Yes, we can use same aspnet_regiis for app.config file as well :)

Here are the steps:

  1. Rename app.config file to web.config :)
  2. Add following section on the very first line after <configuration> and save renamed web.config file

<protectedData>

<protectedDataSections>

<add name="appSettings"

provider="DataProtectionConfigurationProvider"

inheritedByChildren="false" />

</protectedDataSections>

</protectedData>

     

    3. Locate aspnet_regiis.exe in c:\windows\microsoft.net\framework\v2.0.#####\ folder

    4. Run following command from command line at c:\windows\microsoft.net\framework\v2.0.#####\:

        > aspnet_regiis -pef "appSettings" <folder path where renamed Web.config is placed> -prov "DataProtectionConfigurationProvider"

    5. After successful run, file will be encrypted

    6. Rename web.config back to the original .config file

    That’s it. I hope this helps!

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading