Use the encrypted database connection string and asp.net string in asp.net

Source: Internet
Author: User

Use the encrypted database connection string and asp.net string in asp.net

When we publish a website, encrypt web. config to effectively ensure the security of database users and passwords. The steps are as follows:

1. Add a key

Run: C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_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: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis-Arg "system. web/identity" "E: \ HS Studio \ Donet2 \ Hnlawyer"-prov

"Hnlaw"

C: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis-Arg "connectionStrings" "E: \ HS Studio \ Donet2 \ Hnlawyer"-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: \ WINDOWS \ Microsoft. NET \ Framework \ v2.0.50727 \ aspnet_regiis-Arg "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, you should note that after you finish the process, find the C: \ Documents ents and Settings \ All Users \ Application Data \ Microsoft \ Crypto \ RSA \ MachineKeys 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 :)


Aspnet standard Secure Connection database connection string VM

<Configuration>
<Deleetask>
<! -- Whether the connection string is encrypted -->
<Add key = "ConStringEncrypt" value = "false"/>
<! -- Database connection string. (If the encryption method is used, set the preceding item to true. The encryption tool can be downloaded from the official website,
If server = 127.0.0.1; database =... is used in plain text, set it to false. -->
<Add key = "ConnectionString" value = "server = 127.0.0.1; database = NewsTest; uid = sa; pwd = 123"/>
<! -- Other module connection strings can be added continuously so that the same project can connect to multiple databases. If not, delete the row -->
<! -- <Add key = "ConnectionString2" value = "server = 127.0.0.1; database = codematic2; uid = sa; pwd = 1"/> -->
</AppSettings>
<Configuration>

Aspnet database connection string

Certainly not. Since it is encrypted, it will be decrypted when it is used. Even if you change it to a plaintext connection string, the program still considers it as a ciphertext and decrypts it, after your brother's plaintext "decryption", it is estimated that the program will not be used. use reflector to check the source code and obtain the decryption algorithm.

Related Article

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.