【问题标题】:Using RSACryptoServiceProvider on Azure web site results in file not found error在 Azure 网站上使用 RSACryptoServiceProvider 会导致找不到文件错误
【发布时间】:2015-01-18 22:21:23
【问题描述】:

我正在将现有(并且正在运行)的 ASP.NET 网站移动到 Azure 网站。该站点的功能之一是签署 XML 文档。获取密钥的代码是:

// retrieve a key from the key safe - this will create it if it does not exist yet
System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
System.Security.Cryptography.RSACryptoServiceProvider key = new RSACryptoServiceProvider(csp);

最后一行抛出 CryptographicException,并显示消息“系统找不到指定的文件”。

我没有将密钥或容器放入 Azure - 我的理解是 ServiceProvider 会创建一个。 我查看了this article,但没有得到任何线索。

显然我遗漏了一些基本的东西。

【问题讨论】:

标签: c# asp.net azure cryptography


【解决方案1】:

感谢 Simon - 这为我指明了正确的方向。

事实证明,您需要指定在机器存储中创建密钥。有效的代码是:

System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
csp.Flags = CspProviderFlags.UseMachineKeyStore;

注意添加了指定“UseMachineKeyStore”的行

【讨论】:

  • 我们遇到了类似的问题,最终指定了一个临时密钥——无论出于何种原因,UseMachineKeyStore 始终抛出“找不到文件路径”异常。在不了解 Azure 网站在做什么的情况下,显然机器密钥存储路径在这种情况下不起作用,并且临时密钥没有持久化,并且工作正常。不过,这取决于应用程序。
猜你喜欢
  • 1970-01-01
  • 2013-10-27
  • 2016-03-30
  • 1970-01-01
  • 2017-08-27
  • 2022-01-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多