In ASP. NET 2.0, encrypt the website configuration file (Web. cofig) (Abstract)

Source: Internet
Author: User

In ASP. NET 2.0, the website configuration file (Web. cofig) is encrypted.

 

You do not need to write anyCodeYou only need to use the aspnet_regiis tool to modify the configuration file. For example, we need to encrypt the following configuration file:

<Configuration>
<Connectionstrings>
<Add name = "sqlservices" connectionstring = "Data Source = localhost;
Integrated Security = sspi; initial catalog = northwind; "/>
</Connectionstrings>
</Configuration>

Assume that the configuration file is in the myapplication directory.
Encryption command: aspnet_regiis-pe "connectionstrings"-app "/myapplication"

The aspnet_regiis command is in the. NET Framework directory you have installed. The default value is C:/Windows/Microsoft. NET/framework/v2.0 .*

Encrypted effect:
<Configuration>
<Connectionstrings configprotectionprovider = "rsaprotectedconfigurationprovider">
<Encrypteddata type = "http://www.w3.org/2001/04/xmlenc#Element"
Xmlns = "http://www.w3.org/2001/04/xmlenc#">
<Encryptionmethod algorithm = "http://www.w3.org/2001/04/xmlenc#tripledes-cbc"/>
<Keyinfo xmlns = "http://www.w3.org/2000/09/xmldsig#">
<Encryptedkey xmlns = "http://www.w3.org/2001/04/xmlenc#">
<Encryptionmethod algorithm = "http://www.w3.org/2001/04/xmlenc#rsa-1_5"/>
<Keyinfo xmlns = "http://www.w3.org/2000/09/xmldsig#">
<Keyname> RSA key </keyname>
</Keyinfo>
<Cipherdata> <ciphervalue> 0ru0xfrexc6alfyzm + F + iwzvinqtzaaunysovpv0dlipm72d
34mj/gx7pzvhsjnqclixeyjsayse
12oauf4rlieraa/rhiqdkjqyjtrrrciqnwqt5pet5lm9q0ait20kpb2g2hn/0qb
7vkcwydbotdbwmua7fxaqjhmckavi0mc = </ciphervalue>
</Cipherdata>
</Encryptedkey>
</Keyinfo>
<Cipherdata> <ciphervalue> bpws3liouxhd0qdlfrmwdy9xwn1jphnmoskuvn3jvpw
Kmd21_hjo2betijyioaq/2j1saldjm
Jfgg85bekfvuunbmrg6czcgxhyokeahzghzdw + d
Za8qef/t7witzuiqeslgk2wluxndfg4zfsydivmxy6xqh3fvw4jochzlxg/
Zjpolicychik3i27oh/xuxtsq0vnol
Gfssm/mtgwb4tloelcrj6jm5u0dja2fvmjpdc =
</Ciphervalue>
</Cipherdata>
</Encrypteddata>
</Connectionstrings>
</Configuration>

Note: To avoid a long line, I add several carriage returns to the encrypted information here.

ASP. NET automatically decrypts the content of the Web. config file. Therefore, encryption settings can be decrypted without any additional steps for other ASP. NET functions or to access values in the code.

If you want to modify the configuration information, you need to decrypt the file and then encrypt it. Decrypt the-Pd option using the aspnet_regiis.exe command.
The command is as follows: aspnet_regiis-Pd "connectionstrings"-app "/myapplication"

The example above is for the IIS Site. If your site uses Asp.net Development Server of vs2005
You need to use the-Arg parameter. Of course, the IIS site can also be used as follows:

Aspnet_regiis.exe-Arg "connectionstrings" "E:/myblog/blogcode/Website"

Note:
-You can encrypt the specified configuration section of the web. config file in the specified physical (non-virtual) directory by running.
The corresponding decryption is:
-The PDF parameter decrypts the specified configuration section of the web. config file in the specified physical (non-virtual) directory.

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.