加密非ASP.Net应用程序中的连接字符串

我正在使用C#和WPF,当然还有app.config文件。 我无法找到存储在app.config中的加密连接字符串示例。 有很多ASP.NET和web.config的例子,但app.config没什么可靠的。 我遇到的唯一例子清楚地表明字符串在它首次加密的同一台机器上只是“可解码”(即使是一个字?)。 在app.config中使用加密连接字符串(或其他数据)是否有可行的选项?

在App.config中加密ConnectionStrings

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); } } }