How to encrypt database connection strings in ASP. net2.0
In ASP. net2.0, Web. config is encrypted when a website is published. This effectively ensures the security of database users and passwords. The steps are as follows:
1. Add a key
Run: C: \ WINDOWS \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regiis-PC "hnlaw"-exp
"Hnlaw" is the key name.
2. Add a web. config Node
Add:
<Configprotecteddata>
<Providers>
<Add keycontainername = "hnlaw" usemachinecontainer = "true" Description = "uses rsacryptoserviceprovider to encrypt and
Decrypt "name =" hnlaw "type =" system. configuration. rsaprotectedconfigurationprovider, system. configuration, version = 2.0.0.0,
Culture = neutral, publickeytoken = b03f5f7f11d50a3a "/>
</Providers>
</Configprotecteddata>
Note: Here keycontainername = "hnlaw" and name = "hnlaw" respectively indicate your key name;
3. encrypt web. config
Add a batch file enweb. bat to the root directory of the website. The content is as follows:
@ Echo off
C: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regiis-Arg "system. Web/identity" "E: \ HS studio \ donet2 \ hnlawyer"-prov
"Hnlaw"
C: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regiis-Arg "connectionstrings" "E: \ HS studio \ donet2 \ hnlawyer"-prov
"Hnlaw"
Pause
Register the above path and name!
It appears successfully after running!
4. decryption
Add a batch file deweb. bat to the root directory of the website. The content is as follows:
@ Echo off
C: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regiis-Arg "system. Web/identity" "E: \ HS studio \ donet2 \ hnlawyer"
C: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ aspnet_regiis-PDF "connectionstrings" "E: \ HS studio \ donet2 \ hnlawyer"
Pause
Finally, you should note that after you finish the process, find the c: \ Documents ents and Settings \ All Users \ Application Data \ Microsoft \ crypto \ RSA \ machinekeys directory and find the generated
The key file (which can be searched by Time) can be read by the network service. Otherwise, an error message from the provider: The RSA key container cocould will appear.
Not be opened.
Unable to read
This may happen. If you do not have your own server and you do not have the permission to modify the machinekeys directory, there are other solutions. I hope you can share them with us.
This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/21aspnet/archive/2007/03/20/1535701.aspx