Encryption and decryption of configuration files in ASP. net2.0

Source: Internet
Author: User
Configuration file encryption and decryption (reproduced) http://pw.cnblogs.com/archive/2006/06/25/435357.html in ASP. net2.0

The encryption operation is as follows: Private   Void Protectsection ( String Sectionname, String Provider)
{
Configuration config =
Webconfigurationmanager.
Openwebconfiguration (request. applicationpath );

Configurationsection Section = Config. getsection (sectionname );

If (Section ! =   Null   &&   ! Section. sectioninformation. isprotected)
{
Section. sectioninformation. protectsection (provider );
Config. Save ();
}
}

The decryption operation is as follows:   Private   Void Unprotectsection ( String Sectionname)
{
Configuration config =
Webconfigurationmanager.
Openwebconfiguration (request. applicationpath );

Configurationsection Section = Config. getsection (sectionname );

If (Section ! =   Null   && Section. sectioninformation. isprotected)
{
Section. sectioninformation. unprotectsection ();
Config. Save ();
}
}

Configuration file before encryption: <? XML version = "1.0" ?>
< Configuration >
< Appsettings >
< Add Key = "Name" Value = "Shy520"   />
< Add Key = "Address" Value = "Cnblogs"   />
  </ Appsettings >
< System . Web >
< Compilation Debug = "True" />
</ System. Web >
</ Configuration >

Encrypted configuration file: <? XML version = "1.0" ?>
< Configuration >
< Appsettings Configprotectionprovider = "Dataprotectionconfigurationprovider" >
< Encrypteddata >
< Cipherdata >
< Ciphervalue >
Aqaaancmnd8bfderjhoawe/Cl + S
Baaaabi1atlnkeugef0xywgl2xg
Qaaaacaaaaadzgaaqaaaabaaa
Abihxmwlazantwiipst1cdxaaaa
Aasaaacgaaaaeaaaapz/ykyx07c
B + h4fqdr4fklgaaaax1ieyc + wsx
Afsdw1vn2c/fxsg2tanyeugacov
8e3ngfthhsh91gliqkregfpyzgr
Vw1xrez/3vwomji9es7efkrcxej
Nnhl66kg2inrk3ntlnzlztt89cz
9w63u47vkajs6miwsgbz2gntl/9
Ughlelig1_cr3yj + lsjoscexqnv
Hgva48efxpd + teifbtgxehsfkqx
Cqgysshx16vct2gunuc3zmeahbh
Usafkpiyqelyhd4 + m9a/xpe2tqw
Gibla1wbw2ndefrzjpwnkfmpnqr
Hxijkimipwxbdvyy6o0uaaaas8d
Suynohj7qajja2c/4euc7sks =
</ Ciphervalue >
</ Cipherdata >
</ Encrypteddata >
  </ Appsettings >
< System . Web >
< Compilation Debug = "True" />
</ System. Web >
</ Configuration >

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.