【发布时间】: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