Encryption and decryption of database connection strings in ASP. NET web. config and web. config

Source: Internet
Author: User

Encryption and decryption of database connection strings in ASP. NET web. config and web. config

Although not very fresh, I believe there are still many people who don't know, well, don't talk nonsense, just give the method: Start ---> Run, Enter cmd, and then enter the following content

Encryption:

C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis.exe-Arg "connectionStrings" "Your Web project path"

Decryption:

C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis.exe-pdf "connectionStrings" "Your Web project path"

. NET is the version path, and the name of the connectionStrings connection string is modified by yourself.

Note that a local key is used in the encryption process, which means that the decryption process must be completed on the same computer. If the encrypted Web. config file is moved to another computer, the connection string in the Web. config file cannot be decrypted normally.

Comparison before and after encryption:

1. Before Encryption

<configuration>  <connectionStrings>    <add name="ConnectionName" connectionString="Server=127.0.0.1;Database=TestDB;User ID=sa;Password=ok"     providerName="System.Data.SqlClient" />  </connectionStrings></configuration>

2. After Encryption

<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>fDfW3bnVt21RF3N39vDoPphEmDYbUX4cmciD/3+LMY0yRLHckyulnnyBLoflB7DUjyXXms0V33e7MOKt+u2TAocn6x+QHo9Z4Onf1fV0nEq6uTprWZ04M8SLbKp+Vg63JLtYQUft6xF+Bi/aN/ZJ3PYal93bdfNJjtXA2xsb82k=</CipherValue>          </CipherData>        </EncryptedKey>      </KeyInfo>      <CipherData>        <CipherValue>92WEStBHBh0zeu705wseRUajhAHumV9uCrmFJWII8SrhQpjEDrSl0OAfhwYFENr4xpHSfkNDTEFVV5D4MXr3meMsCcp+oYEQxQ/mg1QYLe9mGD+NEaBnv95WzaDcdDyE1SkNKkq01pX94OUV1OygsQtEx1fCZd6le8fd7kx4PAFKDD0he6ajzNFmCoFxg1Dd1+MD3mukgFef64NbjYovTNW8v2G67wLE8vnrokxIvs6+0+rnpLepDAyiEDaL2D3jJWNcQrl+UXI=</CipherValue>      </CipherData>    </EncryptedData>  </connectionStrings></configuration>

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.