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>