【问题标题】:Encrypt Web.config Windows Azure加密 Web.config Windows Azure
【发布时间】:2015-01-02 18:31:19
【问题描述】:

我正在使用来自 Windows Azure 的共享网站。我想加密我的 web.config 的一部分,但是,我收到了这个错误:

使用提供程序“RsaProtectedConfigurationProvider”解密失败。来自提供者的错误消息:无法打开 RSA 密钥容器。

我的网站中有一个页面会加密该文件,但它确实会加密,但是几个小时后我收到了这个错误。我需要将我的机器密钥发送到 Azure 还是他们有我可以使用的?

为了加密我的配置文件,我使用以下代码:

    /// <summary>
    /// About view for the website.
    /// </summary>
    /// <returns>Action Result.</returns>
    public ActionResult About()
    {
        Configuration objConfig =
          WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);
        AppSettingsSection objAppsettings =
          (AppSettingsSection)objConfig.GetSection("appSettings");
        if (!objAppsettings.SectionInformation.IsProtected)
        {
            objAppsettings.SectionInformation.ProtectSection(
                           "RsaProtectedConfigurationProvider");
            objAppsettings.SectionInformation.ForceSave = true;
            objConfig.Save(ConfigurationSaveMode.Modified);
        }

        return View();
    }

【问题讨论】:

  • 我不确定您是如何加密/解密的,但 Azure 中的机器密钥与您在本地拥有的不同。而且我相信每个实例都会有不同的机器密钥。因此,无论您如何加密,都必须牢记这一点。您能否向我们提供有关您如何进行此加密/解密的更多信息?
  • 我添加了一些新代码,谢谢。我注意到加密的代码工作了几个小时,然后就中断了。似乎我的代码被发送到一个新实例,它有它的 on 键。

标签: azure


【解决方案1】:

这可能不是您要查找的内容,但您可以使用 Azure 仪表板中的“配置”选项卡在运行时覆盖 AppSettings,这样 web.config 就不会存储任何实际的敏感数据。

http://www.windowsazure.com/en-us/manage/services/web-sites/how-to-configure-websites/#howtochangeconfig

应用程序设置 - 指定将由您的 Web 应用程序在启动时加载的名称/值对。对于 .NET 站点,这些设置将在运行时注入到您的 .NET 配置 AppSettings 中,覆盖现有设置。对于 PHP 和 Node 站点,这些设置将在运行时作为环境变量提供。

【讨论】:

    【解决方案2】:

    我不确定在您提出问题时这是否可用,但是 Microsoft 的一位工程师提出了一个新的 ProtectedConfigurationProvider 仅适用于 Windows Azure。这是它的链接:https://code.msdn.microsoft.com/Encrypt-Configuration-5a8e8dfe#content

    他们提供了详细的步骤,说明在 here 上应该做什么。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-06-26
      • 2010-11-07
      • 1970-01-01
      • 2014-10-26
      • 1970-01-01
      • 1970-01-01
      • 2016-12-30
      • 2012-08-31
      相关资源
      最近更新 更多