I am trying to encrypt the appSettings and connectionStrings section in the App.config file of the console application. For some reason, section.SectionInformation.IsProtected always returns 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(); } }
Not sure why it always returns true.
azamsharp
source share