【问题标题】:Hiding Important Data隐藏重要数据
【发布时间】:2012-04-22 16:24:10
【问题描述】:

只是想问一下在 .Net 桌面应用程序中隐藏敏感数据(ftp 帐户、数据库连接字符串等)的最佳方法是什么。请有任何建议.. :)

我知道将数据放入应用程序,并记住如果应用程序将被反混淆或反编译,隐藏的数据将被暴露。

我尝试使用应用程序设置

Properties.Settings.Default.MyConnectionString = theConString;

但反编译时仍然可以看到数据。

请有任何建议。

【问题讨论】:

  • 你真的不能那样做。如果应用程序可以访问数据,那么运行它的任何人都可以。如果您想隐藏一些敏感数据,请不要将它们放在应用程序中。
  • @svick 的观点很重要——你在保护谁?如果您试图阻止确定的应用程序最终用户看到它们,那么可能根本无法将它们存储在应用程序中。也就是说,有种安全存储它们的方法,以防止最终用户 PC 上的未经授权的用户(例如病毒)读取它们。

标签: c#


【解决方案1】:

您可以加密全部或部分 app.config 文件。这对于保护数据库连接字符串尤其常见。

这里是一个detailed article,关于如何做到这一点。简而言之,这里是加密 app.config 中连接字符串部分的代码:

static void ToggleConfigEncryption(string exeConfigName)
{
    // Takes the executable file name without the
    // .config extension.
    try
    {
        // Open the configuration file and retrieve 
        // the connectionStrings section.
        Configuration config = ConfigurationManager.
            OpenExeConfiguration(exeConfigName);

        ConnectionStringsSection section =
            config.GetSection("connectionStrings")
            as ConnectionStringsSection;

        if (section.SectionInformation.IsProtected)
        {
            // Remove encryption.
            section.SectionInformation.UnprotectSection();
        }
        else
        {
            // Encrypt the section.
            section.SectionInformation.ProtectSection(
                "DataProtectionConfigurationProvider");
        }
        // Save the current configuration.
        config.Save();

        Console.WriteLine("Protected={0}",
            section.SectionInformation.IsProtected);
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.Message);
    }
}

【讨论】:

    猜你喜欢
    • 2016-01-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-23
    • 1970-01-01
    • 2021-12-19
    相关资源
    最近更新 更多