HTML5先行者高级交流群
欢迎加入学习讨论
专注前端,专注网页设计制作及网站开发项目 - (低价承接网站开发项目) QQ:370158739
加入收藏
RSS
首页
JS下载
CSS3手册
Json在线解析
html5教程
网站及特效实例
视频教程
html5资讯
网络编程
html5书籍
HTML5演示
论坛
入门教程
高级应用
滚动新闻
html5实验
javascript特效
Photoshop教程及网页素材
jquery特效
html5视频教程
CSS3视频教程
JS视频教程
JUQERY视频教程
Bootstrap视频教程
html5video
微信服务号开发教程
最新资讯
最新动态
IT动态
ASP编程
PHP编程
正则表达式
AJAX相关
ASP.NET
JSP编程
Flex
脚本加解密
网页编辑器
相关技巧
黑客相关
网页播放器
其它综合
java教程
您的位置
:
首页
>
网络编程
>
ASP.NET
» 正文
ASP.NET2.0中配置文件的加密与解密_.NET教程_编程技术
2013-12-20 14:04:00
[
小
大
]
已经帮助:
人解决问题
asp.net|加密|解密
首先添加引用: 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
>
z35HTML5中文学习网 - HTML5先行者学习网
z35HTML5中文学习网 - HTML5先行者学习网
来顶一下
返回首页
(责任编辑:)
推荐书籍
推荐资讯
html5及css3做的3D小
html5视频应用
友情链接:
联系人:QQ370158739
关于HTML5先行者
-
联系我们
-
广告服务
-
友情链接
-
网站地图
-
版权声明
-
人才招聘
-
帮助