zoukankan
html css js c++ java
ASP.NET2.0中配置文件的加密与解密
首先添加引用: using System.Web.Configuration;
加密操作如下:
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();
}
}
解密操作如下:
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();
}
}
实践:
加密前的配置文件:
<?
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
>
加密后的配置文件:
<?
xml version="1.0"
?>
<
configuration
>
<
appSettings
configProtectionProvider
="DataProtectionConfigurationProvider"
>
<
EncryptedData
>
<
CipherData
>
<
CipherValue
>
AQAAANCMnd8BFdERjHoAwE/Cl+s
BAAAABi1ATlNkEUGEf0XyWGL2Xg
QAAAACAAAAAAADZgAAqAAAABAAA
ABIhxMWlazAntwIIpST1CDXAAAA
AASAAACgAAAAEAAAAPz/YKYx07c
b+h4fqdr4fkLgAAAAX1Ieyc+WSx
AfsDW1vn2C/fXsG2TAnYeUgaCov
8e3nGFTHHsH91gLiqKregFPYzGR
vW1xrez/3VwOmJI9eS7EFKrcXej
NnHL66kg2iNRk3ntLNZlZtTs3cZ
9w63u47VKAjs6miWsGBz2GntL/9
UGHLELigrJcr3YJ+lsjOscExQnv
HGvA48EfxpD+tEiFBtgXeHsFkQX
cqGySshx16vCt2GUNUC3ZmEAhBh
UsAFkPIYqelYHd4+m9a/xPe2tqw
GIbla1wbW2NDEfrzJPwnkfmpNqR
hXijKImipwXbDVYy6o0UAAAAs8D
suYNOhJ7qAjJa2c/4eUC7sks=
</
CipherValue
>
</
CipherData
>
</
EncryptedData
>
</
appSettings
>
<
system
.web
>
<
compilation
debug
="true"
/>
</
system.web
>
</
configuration
>
查看全文
相关阅读:
zookeeper logs is missing zookeeper 日志丢失
Java Spring IoC 学习(3)
jsp中include的两种用法
java多态
Referenced file contains errors
类的初始化顺序
PHP处理session跨域
Apache中按天分割日志(Windows)
redis和memcached的区别(总结)
PHP中的traits简单理解
原文地址:https://www.cnblogs.com/pw/p/435357.html
最新文章
解决Table不继承父节点的属性的方法
嵌入式Linux-Bmp转jpeg
Linux嵌入式学习-ds18b20驱动
Linux嵌入式学习-烟雾传感器驱动-字符设备驱动-按键驱动
Qt学习笔记-Qt5和Qt4在音频方面的不同-QtAV
Qt学习笔记-Qt-4.8.6+phonon+mplayer
Linux嵌入式学习-mount命令+nfs挂载失败原因【转】
Linux嵌入式学习-网络配置-ping外网、主机和域名
Linux嵌入式学习-Mplayer交叉编译-undefined reference to `clock_gettime' MPlayer
Linux嵌入式学习-交叉编译mplayer
热门文章
Qt学习笔记-安装phonon模块
Linux嵌入式学习-USB端口号绑定
Linux嵌入式学习-交叉编译openssl
Qt学习笔记-中文乱码-QtWebkit显示网页乱码的问题QFont::setPixelSize: Pixel size <= 0 (0)
嵌入式LInux-让开发板访问外网-ping bad address baidu.com
Qt学习笔记-Qtcreator的webkit和qt4.7.0的版本有关
jQuery获取元素
jQuery加减
JS数组
为什么要用接口
Copyright © 2011-2022 走看看