Encrypt connection string in NON ASP.Net applications

I work with C # and WPF and, of course, with the app.config file. I could not find an example of encrypted connection strings stored in app.config. There are many examples for ASP.NET and web.config, but nothing is enough for app.config. The only examples I came across clearly indicate that the string is only "able to decrypt" (is that even a word?) On the same computer on which it was first encrypted. Are there any viable options for working with encrypted connection strings (or other data) in app.config?

+3
source share
1 answer

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); } } } 
+5
source

Source: https://habr.com/ru/post/1397213/


All Articles