Sometimes we need to store a lot of confidential data in web.config in our production environment (for examples: username\password for impersonation or for connect to database, some appSettings, etc.). And it is not secure to store that as clear text, obviously some people on your server may have access to this file and steal your data.
.NET Framework gives us a good solution. We can encrypt configuration sections in web.config files.
How to Encrypt a section
1. Find aspnet_regiis.exe on your PC.
2. Grand access to ApplicationPool Identity for NetFrameworkConfigurationKey RSA key contanier:
aspnet_regiis -pa "NetFrameworkConfigurationKey" "<ApplicationPool Identity user>"3. Encrypt a section:
aspnet_regiis -pe "<Path/to/section>" -app "/<YouWebApplication>"*All these commands require administrative privileges, so if you want to use command prompt for it - don't forget to 'run as administrator'. Otherwise you will get a lot of very strange errors.
It looks very simple...
But let's consider all these steps in more detail.