首页 新闻 赞助 找找看

aspnet_regiis 加密web.config文件

0
悬赏园豆:20 [已关闭问题] 关闭于 2015-10-06 14:23

能不能做到加密appSettings里面的某一个key,而不是把appSettings全部加密了。

清海扬波的主页 清海扬波 | 小虾三级 | 园豆:825
提问于:2015-09-24 10:21
< >
分享
所有回答(3)
0

这个你自己写个加解密的类就行了

MrNice | 园豆:3450 (老鸟四级) | 2015-09-24 14:59
0

加密:

// Get the current configuration file.
Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

// Get the section.
ConfigurationSection appSec = config.GetSection("appSettings");

if (appSec != null && !appSec.SectionInformation.IsProtected)
 {
     // Protect (encrypt)the section.
    appSec.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");

     // Save the encrypted section.
    appSec.SectionInformation.ForceSave = true;
     config.Save();
 }

解密:

 

Configuration config = WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

 ConfigurationSection section = config.GetSection("appSettings");

if (section != null && section.SectionInformation.IsProtected)
 {
     section.SectionInformation.UnprotectSection();
     config.Save();
 }

不过有一点要注意,当你将加密后的website移到另一台IIS上时它是不能进行解密的,因为加密的key是放在本地机器的。此时你需要在另一台server上重新使用aspnet_regiis进行加密。

JackWang-CUMT | 园豆:2866 (老鸟四级) | 2015-09-24 15:03
0

程序里边加密一次,这里就可以放加密的东西了。

gw2010 | 园豆:1487 (小虾三级) | 2015-09-30 17:07
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册