我正在将现有(且正在运行)的 ASP.NET 网站移动到 Azure 网站。该站点的功能之一是签署 XML 文档。获取 key 的代码是:
// 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,并显示消息“系统找不到指定的文件”。
我还没有将 key 或容器放入 Azure - 我的理解是服务提供商会创建一个。 我已经评论过this article ,但没有得到任何线索。
显然我错过了一些基本的东西。
最佳答案
谢谢西蒙 - 他为我指明了正确的方向。
事实证明,您需要指定在机器存储中创建 key 。有效的代码是:
System.Security.Cryptography.CspParameters csp = new CspParameters();
csp.KeyContainerName = "MyKeyName";
csp.Flags = CspProviderFlags.UseMachineKeyStore;
注意添加了指定“UseMachineKeyStore”的行
关于c# - 在 Azure 网站上使用 RSACryptoServiceProvider 会导致文件未找到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27050054/