加密 app.config 后无法识别的属性“configProtectionProvider" [英] Unrecognized attribute 'configProtectionProvider' after encrypting app.config
问题描述
我在我的应用程序开始时运行以下方法,传入一个位于 applicationSettings 下的部分:
I run the following method at the beginning of my application passing in a section living under applicationSettings:
public static void EncryptConfigSection(string sectionKey)
{
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
ConfigurationSection section = config.GetSection(sectionKey);
if (section != null)
{
if (!section.SectionInformation.IsProtected)
{
if (!section.ElementInformation.IsLocked)
{
section.SectionInformation.ProtectSection("RSAProtectedConfigurationProvider");
section.SectionInformation.ForceSave = true;
config.Save(ConfigurationSaveMode.Full);
ConfigurationManager.RefreshSection(sectionKey);
}
}
}
}
以下是 app.config 部分的示例:
Here's an example of the section in the app.config:
<applicationSettings>
<Example.Properties.Settings>
<setting name="Key" serializeAs="String">
<value>Value</value>
</setting>
</Example.Properties.Settings>
</applicationSettings>
当我尝试访问该部分的任何设置时,收到以下错误:
When I try to access any of the settings from the section, I receive the following error:
无法识别的属性configProtectionProvider"
Unrecognized attribute 'configProtectionProvider'
这是一个桌面应用,启动时需要加密一些设置,退出时需要解密.
This is a desktop application that needs to encrypt some settings when starting then decrypt when exiting.
有没有人有解决这个问题的方法?
Does anyone have a solution for this issue?
推荐答案
我无法在应用程序运行时加密/解密配置文件并继续读取值.
I was not able to encrypt/decrypt the config file while the application was running and continue to read the values.
虽然不是我想要的,但解决问题的方法是在应用程序运行之前先加密/解密 .config.
Although not what I wanted, the solution to the problem was to first encrypt/decrypt the .config before the application ran.
这是另一种我没有做过但看起来很有趣的方法:加密.NET app.config 文件中的密码
Here is another approach which I didn't do but seemed interesting: Encrypting Passwords in a .NET app.config File
这篇关于加密 app.config 后无法识别的属性“configProtectionProvider"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!