How do I encrypt a database join string

  • 2020-05-05 11:04:41
  • OfStack

How do I encrypt the database join string

In asp.net2.0, when publishing a website, encrypt web.config to ensure the security of database users and passwords. The steps are as follows:

1. Add the key

C:\WINDOWS\ Microsoft.NET \Framework\ v2.0.50727 \ aspnet_regiis-hnlaw "-exp

Where "hnlaw" is the key name

2. Add web.config node

In web. config < configuration > < /configuration > Between:

< 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 represent your key name;

3. Encrypt web.config

Add a batch file enweb.bat to the root of the site,

@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 the path and name above!

Run after success!

4. Decryption

Also add a batch file deweb.bat to the root of the site,

@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

Finally, note: when you are done, find C:\Documents and Settings\All Application \ Data\Microsoft\Crypto\RSA\MachineKeys

Error message from provider: The RSA Microsoft could could

not be opened.

Unable to read

This may occur, if you do not have their own server, no permission to modify the MachineKeys directory, do not know there are other solutions, I hope you share :)

 


Related articles: