国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

淺談ASP.NET2.0中配置文件的加密與解密_.Net教程

2024-07-10 12:50:57
字體:
供稿:網(wǎng)友

推薦:ASP.NET遍歷配置文件的連接字符串
在ASP.NET 2.0中,提供了更方便的配置文件訪問的類,具體可以到System.Configuration名稱空間下進行查看。本文提供一種在開發(fā)過程中常用的得到數(shù)據(jù)庫字符串的方法,為方便使用,寫成一個方法進行調(diào)用: 以下為引用的內(nèi)容: public string GetConnectionStrin

首先添加引用: using System.Web.Configuration;

加密操作如下:

以下為引用的內(nèi)容:

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();
}
}

解密操作如下:

以下為引用的內(nèi)容:


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();
}
}


實踐:

加密前的配置文件:

以下為引用的內(nèi)容:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="name" value="shy520" />
<add key="address" value="VeVb" />
</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>

分享:探討.Net整合其他平臺
整合分布式應(yīng)用程序經(jīng)常是一件非常困難并且錯綜復雜的任務(wù),即使是最富有經(jīng)驗的開發(fā)者也可能會覺得頭疼。當應(yīng)用程序在不同的操作系統(tǒng)以及涉及不同的程序平臺時,這個集成問題變得尤其復雜。雖然說,Web服務(wù)承諾可以減輕程序員完成集成任務(wù)的困難程度,但是也

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 全南县| 邢台县| 南江县| 新乡市| 嵊泗县| 新绛县| 弥渡县| 南召县| 元阳县| 绥芬河市| 建阳市| 班玛县| 韶关市| 滕州市| 阳山县| 黄浦区| 蒙城县| 灯塔市| 丰县| 彭州市| 泰兴市| 清水县| 乳山市| 汝阳县| 毕节市| 绥德县| 米林县| 敦化市| 志丹县| 荃湾区| 台前县| 南丹县| 江陵县| 江西省| 光泽县| 永顺县| 西贡区| 师宗县| 浮山县| 龙陵县| 苏尼特右旗|