【发布时间】:2017-01-12 14:15:42
【问题描述】:
我们在 Azure 上的两个 Web 应用程序上部署了一个网站:一个生产版本和一个预生产版本。
网站在特定时间创建一个容器来托管 RSA 密钥,使用以下代码:
// -----------------------------
// Part 1 : Initialize csp params
// -----------------------------
const int PROVIDER_RSA_FULL = 1;
const string CONTAINER_NAME = "OurKeyContainer";
CspParameters cspParams;
cspParams = new CspParameters(PROVIDER_RSA_FULL);
cspParams.KeyContainerName = CONTAINER_NAME;
cspParams.Flags = CspProviderFlags.UseMachineKeyStore;
cspParams.ProviderName = "Microsoft Strong Cryptographic Provider";
// --------------------------------------------------
// Part 2 : A try to set folder access rights to "everyone"
// --------------------------------------------------
// http://whowish-programming.blogspot.fr/2010/10/systemsecuritycryptographycryptographic.html
// http://stackoverflow.com/questions/5013881/c-sharp-how-do-i-get-the-everybody-user
var sid = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
var rule = new CryptoKeyAccessRule(sid, CryptoKeyRights.FullControl, AccessControlType.Allow);
cspParams.CryptoKeySecurity = new CryptoKeySecurity();
cspParams.CryptoKeySecurity.SetAccessRule(rule);
return new RSACryptoServiceProvider(cspParams);
问题是此代码仅适用于其中一个网站,即实际首次启动的网站。第二个抛出 CryptographicException “对象已存在”。
谷歌搜索后,该问题似乎是由执行网站的用户无权访问密钥容器引起的,但不幸的是,推荐的修复(在我们上面代码的第 2 部分中实现)不起作用..
有什么想法或建议吗?
谢谢
丽安娜
【问题讨论】:
-
您是否尝试过 Granting Read Access to an RSA Encryption Key 通过 KUDU 获取您失败的 Web 应用程序的身份?您可以找到 Aspnet_regiis.exe 文件的位置here。
-
嗨,布鲁斯,感谢您的回复。我阅读了您发送的网址,但 Azure 控制台和 Kudu 都无法识别 aspnet_regiis 命令。有什么建议吗?
-
对于 .NET Framework 版本 4(32 位系统),您可以将您的目录更改为
D:\Windows\Microsoft.NET\Framework\v4.0.30319,对于 .NET Framework 版本 4(64 位系统),您可以更改您的目录通过 KUDU 到D:\Windows\Microsoft.NET\Framework64\v4.0.30319。 -
我设法运行the recommended command¶它告诉我它已经成功,然后我重新启动了我的网站.. 但不幸的是,我仍然有同样的例外.. :-( .
标签: .net azure cryptography azure-web-app-service cryptographicexception