Use the command line tool aspnet_regiis.exe
You can also use the aspnet_regiis.exe command line tool to encrypt and decrypt the Web. config file configuration section. You can find this tool in the "% WINDOWSDIR % \ Microsoft. Net \ Framework \ version" directory. To encrypt a section in the Web. config file, you can use the DPAPI machine key in this command line tool, as shown below:
Common form of encrypting the Web. config file of a specific website:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-Arg section physical_directory-prov provider
Or:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-pe section-app virtual_directory-prov provider
Encrypt the specific instance of the Web. config file of a specific website:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-Arg "connectionStrings" "C: \ Inetpub \ wwwroot \ MySite"-prov "DataProtectionConfigurationProvider"
Or:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-pe "connectionStrings"-app "/MySite"-prov "DataProtectionConfigurationProvider"
Common form of decrypting the Web. config file of a specific website:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-pdf section physical_directory
Or:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-pd section-app virtual_directory
Decrypts a specific instance of the Web. config file of a specific website:
Copy codeThe Code is as follows:
Aspnet_regiis.exe-pdf "connectionStrings" "C: \ Inetpub \ wwwroot \ MySite"
Or:
You can also specify that aspnet_regiis.exe is used to encrypt/decrypt the machine. config file.
[Prompt] encrypt configuration settings in ASP. NET version 1.x
To protect configuration settings in ASP. NET version 1.x, developers need to encrypt and store sensitive settings in the web server registry, and store them in a "strong" key mode. The configuration file does not store encrypted content (such as ASP. NET 2.0), but only contains a reference to the registry key that stores the encrypted value. For example:
Copy codeThe Code is as follows:
<Identity impersonate = "true"
UserName = "registry: HKLM \ SOFTWARE \ MY_SECURE_APP \ identity \ ASPNET_SETREG, userName"
Password = "registry: HKLM \ SOFTWARE \ MY_SECURE_APP \ identity \ ASPNET_SETREG, password"/>
Microsoft released the aspnet_setreg.exe command line tool for developers to encrypt sensitive configuration information and move it to a "strong" Registry portal. Unfortunately, this tool only works for specific configuration settings; in contrast, ASP. NET 2.0 allows encryption of any configuration section.
For more information about using aspnet_setreg.exe in an ASP. NET 1.xapplication, see KB #32990 in MSDN. Unfortunately, this command line program can only encrypt predefined sections in configuration settings, and does not allow you to encrypt your own database connection strings and other sensitive information.
Encrypted instance:
Copy codeThe Code is as follows:
C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis-pdf connectionStrings I: \ code repository \ wt_Projects \ WebSites \ WebSite