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
>
查看全文
相关阅读:
从键盘输入两个数字,根据订单或大或小的输出
软考路(3)——数据流图的尖
HDU 3988 Harry Potter and the Hide Story(数论-整数和素数)
排序算法门外汉理解-Shell排序
流量计算-Jstorm提交Topology过程(下一个)
CentOS在安装配置 Ngnix_tomcat_PHP_Mysql
C++基于该模型模板包括节目外实例
同ListView该接口无法通过手势滑动左右切换界面问题解决方法
用彩虹表破解MD5、LM Hash等复杂加密密码
logstash
原文地址:https://www.cnblogs.com/pw/p/435357.html
最新文章
一位同学3年通过CPA, CFA, ACCA的经验
linux su,sudo命令
十年linux命令总结
-bash: /bin/rm: Argument list too long的解决办法
ps、top 、free查看用户资源信息
Linux下查看/管理当前登录用户及用户操作历史记录
Linux查看用户数、登录用户
shufe前辈名师
datagridview控件的使用
git svn
热门文章
svn的下载链接
将DevExpress.Utils.ImageCollection变量的image导出
VS不显示最近打开的项目
Winform中使用折叠窗口
C#中配置文件保存的路径
VS中sln和suo的区别
string类的常用方法
FieldOffset
算法---高速分拣(quick sort)
白学jquery Mobile《构建跨平台APP:jQuery Mobile移动应用实战》连续7-电话问卷调查
Copyright © 2011-2022 走看看