Introduction to ASP. NET configuration file encryption and asp.net configuration file

Source: Internet
Author: User

Introduction to ASP. NET configuration file encryption and asp.net configuration file

In an ASP. in the. NET project, when the project is deployed to the production environment, the Leader asks the configuration file (such as web. config, app. config.

The first method is to write an encryption and decryption algorithm to save the values in these configuration files in the config file as ciphertext, then decrypt it. This method is directly denied, because in the Code, the config values obtained are scattered and it is difficult to modify them one by one.

I found a perfect solution, which is simple, fast, and does not modify any code. Let's take a look at the solution:

ASP. NET 2.0 provides a protection configuration model to encrypt and decrypt the sections information in web. config. RSAProtectedConfigurationProvider: encryption and decryption are performed by default using the RSA public key.

First, execute aspnet_regiis.exe in the Windows command line to encrypt and decrypt data.

Create a new websit project in VS, open web. config, and add a database connection string, such:

 

Then, follow these steps to encrypt and decrypt the data connection string.

 

1. Start Menu> All Programs> Microsoft visual studio 2008> Visual Studio Tools> Visual Studio 2008 developer command prompt (if it is Windows 7, right-click and run it as Administrator)

2. In the command window, enter the command aspnet_regiis.exe-Arg "etettings" C: \ VisualStudio2008 \ Authorization"

-Running the "& lt; & gt. The second "deleettings" is the name of the configuration node you want to encrypt. The third parameter indicates the physical path of web. config.

3. After the command is successfully executed, the message "encryption successful" is displayed.

Now, open the web. config in the program, and the image will look like this.

 

We do not write any code in the program to decrypt the connection string, because. NET will automatically decrypt the connection string for us. If we want to use a connection string, we can call it as usual.

string strconnection = ConfigurationManager.AppSettings["dbconnection"].ToString();

 

If you want to decrypt the file, enter aspnet_regiis.exe-pdf "etettings" C: \ VisualStudio2008 \ Authorization "in the vscommand window"

After successful execution, the decryption is successful.

Open web. config, and we can see the decrypted string.

Friends, is it very convenient.

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.