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 >