c# - 在 Azure 网站上使用 RSACryptoServiceProvider 会导致文件未找到错误

标签 c# asp.net azure cryptography

我正在将现有(且正在运行)的 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/

相关文章:

c# - 如何在不使用 TransactionScope 的情况下使用 EF4 Code First CTP5 分配事务?

asp.net - 中继器 View 状态不刷新输入

c# - 无法将外键插入表中

Azure 逻辑应用程序 - 检查多个条件

azure - Webhook Ms Graph 监听群组对话

c# - System.InvalidOperationException' 出现在 AutoMapper.dll 中。附加信息 : Mapper not initialized

c# - 程序代码主体中元素的首选顺序是什么?为什么?

c# - 只运行最后一个任务!

javascript - 我想要一个 jquery 函数来显示成功登录时隐藏的列表项

python-3.x - 从 Azure Blob 存储、Flask Python、HTML/JS 检索并显示?