Encrypting appSettings Key In ASP.NET Web.config

I needed a solution to encrypt a single key in appSettings section in ASP.NET Web.config file. The article on MSDN Encrypting and Decrypting Configuration Sections tells about encrypting the whole section but I want to hide only a particular key.
It seems that apsnet_regiis could encrypt only sections, so I’ve found a way how to extract this key to another section and encrypt that section in one of StackOverflow answers http://stackoverflow.com/a/6224769

Here are the steps that must be done to get the result:
1. Add a line in configSections with the name of your new section

2. Add new section under configuration

3. In .NET code get the section and key from it

4. After you deploy your Web application to IIS, you should encrypt section secureAppSettings according to the MSDN article mentioned above. Launch Command Prompt as Administrator (it’s important!) and run command (something like this):

Leave a Reply

Your email address will not be published. Required fields are marked *