How to encrypt web. config

Source: Internet
Author: User

1. Open notepad and copy the following code to a new file.
Copy codeThe Code is as follows:
<% @ Page Language = "C #" %>
<%
Response. Write (System. Security. Principal. WindowsIdentity. GetCurrent (). Name );
%>

Save my. aspx to your web directory and run the form to display "nt authority \ network service ". Successful!

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

Aspnet_regiis-pa "NetFrameworkConfigurationKey" "nt authority \ network service"

Note: register the RSA key container of the default RsaProtectedConfigurationProvider,
NetFrameworkConfigurationKey is the default provider of RsaProtectedConfigurationProvider. Successful!

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

Encryption: aspnet_regiis-pe "connectionStrings"-app "/Myweb"
Note: "connectionStrings" is the section to be encrypted. "/Myweb" is the web directory.
Decryption: aspnet_regiis-pd "connectionStrings"-app "/Myweb"

Successful!

4. This can be called in the Program (no decryption is required, haha

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


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:
 Copy codeThe Code is as follows:
<ProtectedData>
<Providers>
<Add name = "MyProvider"
Type = "System. Configuration. RsaProtectedConfigurationProvider, System. Configuration, Version = 2.0. 0.0,
Culture = neutral, PublicKeyToken = b03f5f7f11d0a3a,
ProcessorArchitecture = MSIL"
KeyContainerName = "MyKeys"
UseMachineContainer = "true"/>
</Providers>
</ProtectedData>

Save.

(3) authorize the account to access the computer-level "MyKeys" RSA key container and 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" is the private key container.

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.