asp.net web.config database connection string encryption and decryption _ practical skills

Source: Internet
Author: User

Although not very fresh, but believe that there are many people do not know, good, do not say nonsense, directly to the method: Start---> Run, enter cmd, and then enter the following content

Encryption:

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe-pef "connectionstrings" "Your Web Project path"

Decrypt:

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

. NET is modified for the version path, where connectionstrings the name of the connection string.

It is important to note that a native-based key is used in the encryption process, which means that the decryption process must be done on the same computer. If you move the encrypted Web.config file to another computer, the connection string in the Web.config file will not be decrypted properly.

With encryption before and after comparison:

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#" > &L T 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# "> <encryption Method algorithm= "Http://www.w3.org/2001/04/xmlenc#rsa-1_5"/> <keyinfo xmlns= "http://www.w3.org/2000/09/x"
            mldsig# "> <keyname>rsa key</keyname> </KeyInfo> <CipherData> <ciphervalue>fdfw3bnvt21rf3n39vdopphemdybux4cmcid/3+lmy0yrlhckyulnnybloflb7dujyxxms0v33e7mokt+u2taocn6x+ Qho9z4onf1fv0neq6utprwz04m8slbkp+vg63jltyquft6xf+bi/an/zj3pyal93bdfnjjtxa2xsb82k=</ciphervalue> </Ciph Erdata> </encryptedkey> </KeyInfo> <CipherData> <ciphervalue>92westbhbh0zeu705wseruajhahumv9ucrm Fjwii8srhqpjedrsl0oafhwyfenr4xphsfkndtefvv5d4mxr3memsccp+oyeqxq/mg1qyle9mgd+ neabnv95wzadcddye1sknkkq01px94ouv1oygsqtex1fczd6le8fd7kx4pafkdd0he6ajznfmcofxg1dd1+ Md3mukgfef64nbjyovtnw8v2g67wle8vnrokxivs6+0+rnplepdayiedal2d3jjwncqrl+uxi=</ciphervalue> </CipherData
 > </EncryptedData> </connectionStrings> </configuration>

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.