Web. config database connection
<ConnectionStrings>
<Add name = "EnterpriseWebConnectionString" connectionString = "Data Source =.; Initial Catalog = Enterprise; User ID = sa; Password = 1391018" providerName = "System. Data. SqlClient"/>
</ConnectionStrings>
How to encrypt Data Source =.; Initial Catalog = Enterprise; User ID = sa; Password = 1391018 "providerName =" System. Data. SqlClient?
How to call it in a program? Can you give an example? Is there any small tool for encryption and decryption?
1.. NET itself provides encryption algorithms with An Encrypt namespace, symmetric and asymmetric. Of course, you can also design your own encryption algorithm.
2. connection strings are usually stored in Web applications and Winform applications. config or app. and provides a corresponding Singleton mode class to provide access to the connection string.
3. What you need to do is to use the Singleton class to retrieve the ciphertext of the Connection string before each Connection, decrypt the string, and then pass the plaintext as a parameter to the constructor of the Connection object for Connection.
Encrypted connection string
@ Echo off
C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis.exe-Arg "connectionStrings" "C: \ Program Files \ Microsoft \. NET Pet Shop 4.0 \ Web"
PAUSE
Connection string decryption
@ Echo off
C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis.exe-pdf "connectionStrings" "C: \ Program Files \ Microsoft \. NET Pet Shop 4.0 \ Web"
PAUSE