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
>
查看全文
相关阅读:
WebLogic10 & MyEclipse 配置(转)
java中的接口隔离(ISP)
java多线程之 wait(),notify(),notifyAll()
Windows Server 2008 R2终端服务器激活方法
[zt]PHP+jQuery+Ajax实现用户登录与退出
USACO Window AreaDFS矩形切割
eWebEditor在IE8,IE7下所有按钮无效之解决办法
[zt]【HoorayOS】开源的Web桌面应用框架——安装部署
javascript Date format(js日期格式化)
web design
原文地址:https://www.cnblogs.com/pw/p/435357.html
最新文章
Android Animation Questions
Android Proguard Questions
Android Load Picture Asynchronously
常用的一段ajax的代码
用js实现 类 想到的
minheight最小高度的实现(兼容IE6、IE7、FF)
IE的@cc_on条件编译
frameset, iframe, frame框架页面出现横向滚动条bug的隐藏方法
SqlHelper
操纵页面中iframe里的对象
热门文章
浅谈网页中各种链接引用方法
【转】30分钟regex
Stream 和 byte[] 之间的转换
由模式谈面向对象的基本原则Liskov替换原则
线程池的介绍及简单实现
里氏替换原则
mysql 触发器 存储过程 函数 视图
mysql的索引
小题大做之MySQL 5.0存储过程编程入门
Liskov替换原则
Copyright © 2011-2022 走看看