How to encrypt database connection string in asp.net2.0
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 key
Execute: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis -pc "hnlaw" -exp
where "hnlaw" is the key name
2. Add web.config node
Add between
Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
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:\WINDOWS\Microsoft.NET\Framework\ v2.0.50727\aspnet_regiis -pef "system.web/identity" "E:\HS Studio\Donet2\Hnlawyer" -prov
"hnlaw"
C:\WINDOWS\Microsoft.NET \Framework\v2.0.50727\aspnet_regiis -pef "connectionStrings" "E:\HS Studio\Donet2\Hnlawyer" -prov
"hnlaw"
PAUSE
Register above The path and name!
Success appears after running!
4. Decryption
Similarly 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 -pef "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
The last thing to note is: after finishing, find the C:\Documents and Settings\All Users\Application Data\Microsoft\Crypto\RSA\MachineKeys directory and find the key file that generated
(you can search by time ), give the network service read permission, otherwise an Error message from the provider will appear: The RSA key container could
not be opened.
Cannot be read
This may happen if you don’t have your own server and don’t have permission to modify the MachineKeys directory. I don’t know if there are other solutions. I hope you can share them:)
The above is the detailed content of How to encrypt database connection string in asp.net2.0. For more information, please follow other related articles on the PHP Chinese website!