Не могу понять, почему это работает в сети (меняется на WebConfigManager), а не в winapp. Когда я смотрю на файл конфигурации, он все еще не зашифрован !!
Вы можете помочь?
EncryptionUtility.ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");
public class EncryptionUtility
{
public static void ProtectSection(string sectionName,string provider)
{
var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var section = config.GetSection(sectionName);
if (section == null || section.SectionInformation.IsProtected) return;
section.SectionInformation.ProtectSection(provider);
config.Save();
}
public static void UnProtectSection(string sectionName)
{
var config = ConfigurationManager.OpenExeConfiguration(System.Windows.Forms.Application.ExecutablePath);
var section = config.GetSection(sectionName);
if (section == null || !section.SectionInformation.IsProtected) return;
section.SectionInformation.UnprotectSection();
config.Save();
}
}