Encryption of projects in Web. config in ASP. NET 2.0

Source: Internet
Author: User
Tags connectionstrings

ASP. NET 2.0 brings us a lot of security improvements, making our web applications more and more secure. In the ASP. NET project, most of our database connection strings are written in the web. config file, and the database user password is at a glance, which is obviously insecure. We may have written some encryption and decryption algorithms to encrypt the data. Now, in ASP. NET 2.0, the system provides us with such a function.

<Connectionstrings>
<Add name = "pubs" connectionstring = "Server = localhost; Integrated Security = true; database = pubs"
Providername = "system. Data. sqlclient"/>
<Add name = "northwind" connectionstring = "Server = localhost; Integrated Security = true; database = northwind"
Providername = "system. Data. sqlclient"/>
</Connectionstrings>

If we have the permission to operate the web server, we can directly use the command line without coding encryption.

Aspnet_regiis-pe "connectionstrings"-app "/sampleapplication"

If we cannot operate the web server, we have to use the code method.

Configuration Config = configuration. getwebconfiguration (request. applicationpath );
Configurationsection section = config. Sections ["connectionstrings"];
Section. protectsection ("dataprotectionconfigurationprovider ");
Config. Update ();

After encryption, we can see

<Connectionstrings>
<Encrypteddata>
<Cipherdata>
<Ciphervalue> aqaaancmndjhoaw... </ciphervalue>
</Cipherdata>
</Encrypteddata>
</Connectionstrings>

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.