加密Web.config Windows Azure

时间:2013-02-22 14:10:26

标签: azure

我正在使用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();
    }

2 个答案:

答案 0 :(得分:4)

它可能不是您正在寻找的,但您可以使用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站点,这些设置将在运行时作为环境变量提供。

答案 1 :(得分:2)

我不确定您的问题是否可用,但Microsoft的工程师为Windows Azure提出了一个新的ProtectedConfigurationProvider。以下是指向它的链接:https://code.msdn.microsoft.com/Encrypt-Configuration-5a8e8dfe#content

他们提供了有关here的具体操作的详细步骤。

相关问题