【发布时间】:2010-09-14 22:09:35
【问题描述】:
我正在尝试加密控制台应用程序的 App.config 文件中的 appSettings 和 connectionStrings 部分。出于某种原因,section.SectionInformation.IsProtected 总是返回 true。
static void Main(string[] args)
{
EncryptSection("connectionStrings", "DataProtectionConfigurationProvider");
}
private static void EncryptSection(string sectionName, string providerName)
{
string assemblyPath = Assembly.GetExecutingAssembly().Location;
Configuration config = ConfigurationManager.OpenExeConfiguration(assemblyPath);
ConfigurationSection section = config.GetSection(sectionName);
if (section != null && !section.SectionInformation.IsProtected)
{
section.SectionInformation.ProtectSection(providerName);
config.Save();
}
}
不知道为什么它总是返回 true。
【问题讨论】:
标签: c# .net encryption configuration