Cryptographic Web.config method Sharing _ Practical Tips

Source: Internet
Author: User

1, open Notepad, and then copy the following code into a new file.

Copy Code code 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". Success!

2, (Key step) run CMD, execute the following

Aspnet_regiis-pa "NetFrameworkConfigurationKey" "NT authority\network SERVICE"

Description: Registers the default RsaProtectedConfigurationProvider RSA key container,
NetFrameworkConfigurationKey is the default provider for RsaProtectedConfigurationProvider. Success!

3, now, you can encrypt web.config, run:

Encryption: Aspnet_regiis-pe "connectionstrings"-app "/myweb"
Description: "ConnectionStrings" is the section to encrypt, "/myweb" is the web directory
Decryption: ASPNET_REGIIS-PD "connectionstrings"-app "/myweb"

Success!

4, so you can call in the program (do not decrypt, haha

):
...
String connstr= configurationmanager.connectionstrings["Myconnstr"]. Connectionstring.tostring ();
...


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

(1), create "MyKeys" Key container, run: aspnet_regiis-pc "MyKeys"-exp
(2), add the following in Web.config:

Copy Code code 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), grant the account access to the computer-level "MyKeys" RSA key container, and run:

Aspnet_regiis-pa "MyKeys" "NT authority\network SERVICE"

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

Encryption: Aspnet_regiis-pe "connectionstrings"-app "/myweb"-prov "MyProvider"

             Description: "connectionstrings" is the section to be encrypted, "/ Myweb "Yes Web directory," MyProvider "own key container

        decryption: ASPNET_REGIIS-PD" connectionstrings "-app"/myweb "-prov" MyProvider "

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.