Home > Backend Development > C#.Net Tutorial > How to encrypt database connection string in asp.net2.0

How to encrypt database connection string in asp.net2.0

巴扎黑
Release: 2017-05-21 11:52:55
Original
1608 people have browsed it

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 of web.config:

decrypt" name ="hnlaw" type="System.Configuration.RsaProtectedConfigurationProvider,System.Configuration, Version=2.0.0.0,

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template