【问题标题】:Encrypt connection string in NON ASP.Net applications在非 ASP.Net 应用程序中加密连接字符串
【发布时间】:2011-06-25 21:53:51
【问题描述】:

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

【问题讨论】:

    标签: c# wpf connection-string app-config


    【解决方案1】:

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

    【讨论】:

    • 我以前遇到过这样的例子。但我的理解是,这些部分只能在同一台机器上加密然后解密。所以它不能在分布式应用程序中工作。
    • 来自this article 看起来这种方法适用于分布式应用程序。
    • 这就是代码存在的原因。我删除了第一个链接并更新了第二个。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多