开发者

Cannot encrypt connectionstrings in winforms but works in web?mmm Can you help

开发者 https://www.devze.com 2022-12-13 16:31 出处:网络
Cannot understand why this works in a web (changing to WebConfigManager) but not in a winapp.When I go a look at the config file is still not encrypted!!Am I missing something?

Cannot understand why this works in a web (changing to WebConfigManager) but not in a winapp.When I go a look at the config file is still not encrypted!!Am I missing something? Can You help?

 EncryptionUtility.ProtectSection("connectionStrings", "DataProtectionConfigurationProvider");

public class EncryptionUtility
    {
        public static void ProtectSection(string sectionName,string pro开发者_JAVA百科vider)
        {
            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();
        }
    }


In winforms you have 3 config files: one in the project, on in the debug directory and one in release directory. Are you sure you trying to encrypt the right one?

0

精彩评论

暂无评论...
验证码 换一张
取 消