Asp. net2.0 encrypted database connection string skills

Source: Internet
Author: User

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: WINDOWSMicrosoft. NETFrameworkv2.0.50727aspnet _ 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: WINDOWSMicrosoft. NETFrameworkv2.0.50727aspnet _ regiis-Arg "system. web/identity" "E: HS StudioDonet2Hnlawyer"-prov

"Hnlaw"
C: WINDOWSMicrosoft. NETFrameworkv2.0.50727aspnet _ regiis-Arg "connectionStrings" "E: HS StudioDonet2Hnlawyer"-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: WINDOWSMicrosoft. NETFrameworkv2.0.50727aspnet _ regiis-Arg "system. web/identity" "E: HS StudioDonet2Hnlawyer"
C: WINDOWSMicrosoft. NETFrameworkv2.0.50727aspnet _ regiis-pdf "connectionStrings" "E: HS StudioDonet2Hnlawyer"
PAUSE

Finally, you should note that after you finish the process, find the C: Documents and SettingsAll Usersapplication DataMicrosoftCryptoRSAMachineKeys 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, you do not know any other solutions. I hope you can share them with us :)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.