加密Web.config Windows Azure

加密Web.config Windows Azure,azure,Azure,我正在使用来自Windows Azure的共享网站。我想对web.config的部分内容进行加密,但出现以下错误: 无法使用提供程序“RsaProtectedConfigurationProvider”进行解密。来自提供程序的错误消息:无法打开RSA密钥容器 我在我的网站上有一个页面,它会加密这个文件,但是,几个小时后我就出现了这个错误。我需要将我的机器密钥发送到Azure还是他们有我可以使用的密钥 要加密配置文件,我使用以下代码: /// <summary> ///

我正在使用来自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();
    }
//
///关于网站的查看。
/// 
///行动结果。
关于()的公共行动结果
{
配置对象配置=
OpenWebConfiguration(Request.ApplicationPath);
应用程序设置分区对象设置=
(AppSettingsSection)对象配置.GetSection(“appSettings”);
如果(!objAppsettings.SectionInformation.IsProtected)
{
objAppsettings.Section信息.ProtectSection(
“RsaProtectedConfigurationProvider”);
objAppsettings.SectionInformation.ForceSave=true;
objConfig.Save(ConfigurationSaveMode.Modified);
}
返回视图();
}

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

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


我不确定在您提出问题时这是否可用,但是Microsoft的一位工程师提出了一个新的仅适用于Windows Azure的ProtectedConfigurationProvider。以下是指向它的链接:


他们提供了详细的步骤,具体说明了如何重新进行

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