【发布时间】:2010-10-08 04:32:45
【问题描述】:
我有一个 ASP.NET Web 服务,它正在接收一个字节数组,该数组表示包含 X.509 证书的 .pfx 文件的内容。服务器端代码使用System.Security.Cryptography.X509Certificate2 构造函数从字节加载证书:
X509Certificate2 native_cert = new X509Certificate2(
pkcs12_buf /*byte array*/,
password,
X509KeyStorageFlags.PersistKeySet |
X509KeyStorageFlags.Exportable
);
根据我的服务进程以谁的身份运行,此调用要么成功,要么因“内部错误”异常而失败。异常堆栈上的最后一次调用是X509Utils._LoadCertFromBlob,这是mscore.dll 中的非托管代码。
此代码在使用服务帐户凭据在交互式登录中从控制台应用程序运行时成功。在使用服务帐户凭据的应用程序池中以w3wp.exe 运行时,它会失败。将应用程序池身份更改为管理员可以解决问题,因此它一定是权限问题,但我不知道为此可能需要什么权限。该代码不涉及文件系统或 Windows 证书存储。
[更新:更多信息]
此错误出现在 Windows 事件日志中:
*Cryptographic Parameters:*
**Provider Name:** Microsoft Software Key Storage Provider
**Algorithm Name:** Not Available.
**Key Name:** {E182E13B-166D-472A-A24A-CBEF0808E9ED}
**Key Type:** User key.
*Cryptographic Operation:*
**Operation:** Open Key.
**Return Code:** 0x2
有什么想法吗?
【问题讨论】:
标签: c# blob x509certificate2