I run the following method at the beginning of my application, passing in the section located in the applicationSettings section:
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); } } } }
Here is an example section in 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 parameters from a section, I get the following error:
Unrecognized attribute 'configProtectionProvider'
This is a desktop application that needs to encrypt some settings at startup, then decrypt on exit.
Does anyone have a solution to this problem?
source share