How does asp.net2.0 encrypt the database connection string? In asp.net2.0, when publishing a website, encrypt web.config, which can effectively ensure the security of database users and passwords. The steps are as follows:
1. Add a key and execute: C :WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pc "hnlaw" -exp
Where "hnlaw" is the key name
2. Add the web.config node between <configuration></configuration> of web.config:
<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" represent your key name respectively;
3. Encrypt web.config
Add a batch file enweb.bat to the root directory of the website with the following content:
@echo off
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pef "system.web/identity" "E:HS StudioDonet2Hnlawyer" -prov
"hnlaw"
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pef "connectionStrings" "E:HS StudioDonet2Hnlawyer" -prov
"hnlaw"
PAUSE
Register the path and name above!
Success appears after running!
4. Decrypt and add a batch file deweb.bat to the root directory of the website with the following content:
@echo off
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pef "system.web/identity" "E:HS StudioDonet2Hnlawyer"
C:WINDOWSMicrosoft.NETFrameworkv2.0.50727aspnet_regiis -pdf "connectionStrings" "E:HS StudioDonet2Hnlawyer"
PAUSE
is: after finishing, find the C:Documents and SettingsAll UsersApplication DataMicrosoftCryptoRSAMachineKeys directory, find the generated
key file (you can search it by time), and give it to the network service Read permission is available, otherwise an Error message from the provider: The RSA key container could
not be opened will appear.
you cannot read
. If you do not have your own server and do not have permission to modify the MachineKeys directory, I don’t know if there are other solutions. I hope you can share them:)