【发布时间】:2013-03-25 23:30:00
【问题描述】:
我有一个带有 connectionStrings 部分的 myapp.somenamespace.exe.config 文件,我需要对其进行加密。还有一些我想要完整的其他配置设置。所以我写了这个小工具来做这件事:
class Program
{
static void Main(string[] args)
{
EncryptSection("myapp.somenamespace.exe.config", "connectionStrings");
}
static void EncryptSection(string fileName, string sectionName)
{
var config = ConfigurationManager.OpenExeConfiguration(fileName);
var section = config.GetSection(sectionName);
if (section.SectionInformation.IsProtected) return;
secction.SectionInformation.ProtectSection("DataProtectionConfigurationProvider");
config.Save();
}
}
会发生什么,它会创建一个名为 myapp.somenamespace.exe.config.config 的新配置文件 - 添加一个重复的 .config 扩展名,该扩展名仅包含加密部分。它不会修改原始配置文件。
有什么想法为什么会出现这种奇怪的行为以及我该如何解决?
【问题讨论】:
标签: c# encryption configuration app-config