Encrypt connection string in NON ASP.Net applications

前端 未结 1 1214
情深已故
情深已故 2020-12-15 14:53

I am working with C# & WPF and, of course, an app.config file. I have not been able to find an example of encrypted connection strings, stored in the app.config. There\'

相关标签:
1条回答
  • 2020-12-15 15:07

    Encrypt ConnectionStrings in App.config

    private void ProtectSection(String sSectionName)
    {
        // Open the app.config file.
        Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        // Get the section in the file.
        ConfigurationSection section = config.GetSection(sSectionName);
        // If the section exists and the section is not readonly, then protect the section.
        if (section != null)
        {
        if (!section.IsReadOnly())
            {
            // Protect the section.
                section.SectionInformation.ProtectSection("RsaProtectedConfigurationProvider");
                section.SectionInformation.ForceSave = true;
                // Save the change.
                config.Save(ConfigurationSaveMode.Modified);
             }
         }
    }
    
    0 讨论(0)
提交回复
热议问题