Get the App
SLTechnology News&Howtos  ›  Development  › 

How to encrypt web.config

Shulou Source: shulou.com Published: 2022-06-03 05:34:29 09月19日 Update

This article mainly introduces how to encrypt web.config, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to know about it.

1. Open notepad and copy the following code to a new file.

The code is as follows:

Save my.aspx to your web directory and run the form to display "NT AUTHORITY\ NETWORK SERVICE". Success!

2. (the key step) run cmd and execute the following

Aspnet_regiis-pa "NetFrameworkConfigurationKey"NT AUTHORITY\ NETWORK SERVICE"

Description: register the default RSA key container for RsaProtectedConfigurationProvider

NetFrameworkConfigurationKey is the default provider for RsaProtectedConfigurationProvider. Success!

3. Now, you can encrypt web.config and run:

Encryption: aspnet_regiis-pe "connectionStrings"-app "/ Myweb"

Note: "connectionStrings" is the section to be encrypted, and "/ Myweb" is the web directory

Decryption: aspnet_regiis-pd "connectionStrings"-app "/ Myweb"

Success!

4. So you can call it in the program (no need to decrypt it,

):

...

String connstr= ConfigurationManager.ConnectionStrings ["myConnstr"] .ConnectionString.ToString ()

...

Similarly, you can also create your own RSA key container, as follows:

(1) create a "MyKeys" key container and run: aspnet_regiis-pc "MyKeys"-exp

(2) add the following to web.config:

The copy code is as follows:

Save.

(3) to grant the account access to the computer-level "MyKeys" RSA key container, run:

Aspnet_regiis-pa "MyKeys"NT AUTHORITY\ NETWORK SERVICE"

(4) now, you can encrypt web.config and run:

Encryption: aspnet_regiis-pe "connectionStrings"-app "/ Myweb"-prov "MyProvider"

Note: "connectionStrings" is the section to be encrypted, "/ Myweb" is the web directory, and "MyProvider" has its own key container.

Decryption: aspnet_regiis-pd "connectionStrings"-app "/ Myweb"-prov "MyProvider"

Thank you for reading this article carefully. I hope the article "how to encrypt web.config" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Encryption run container key code article success directory yes no value key interest at the same time account file more friends permissions knowledge Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Xiaomi macOS Microsoft Huawei