Encrypt and decrypt a section in the ASP.NET web.config file

Published on Saturday, September 5, 2015

First of your need to locate your aspnet_regiis.exe file which is located in one of the directories inside

%systemroot%\Microsoft.Net\Framework\

You can easily navigate to this folder using the WinBtn+R command (Run command) and pasting the above line in the run dialog.

The Framework folder contains your installed .NET versions.

Encrypt section

The below command will encrypt the section in the web config file which is located in the C:\Path\To\My\Folder\Containing\MyWebConfig folder

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -pef "connectionStrings" "C:\Path\To\My\Folder\Containing\MyWebConfig"

Decrypt section

The below command will decrypt the section in the web config file which is located in the C:\Path\To\My\Folder\Containing\MyWebConfig folder

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis.exe -pdf "connectionStrings" "C:\Path\To\My\Folder\Containing\MyWebConfig"

In case of "object not found" error run the command prompt with administrator privileges.

comments powered by Disqus