无法读取 Windows 服务器 2008 上的 p12 文件



我需要从磁盘位置读取p12文件,在我的本地环境中一切正常,但是当我将站点发布到Windows Server 2008时,我收到以下错误:

System.Security.Cryptography.CryptographicException: 内部错误 发生。

在 System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 HR) 在 System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(字符串 文件名, IntPtr 密码, UInt32 dwFlags, 布尔持久键集, SafeCertContextHandle& pCertCtx) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(String 文件名, 对象密码, X509KeyStorageFlags keyStorageFlags) at 系统.安全.密码学.X509证书.X509证书2..ctor(字符串 文件名、字符串密码、X509密钥存储标志键存储标志)

我拥有的代码是:

var certP12 = new X509Certificate2(
@"C:tempfile.p12",
"123456",
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet);

我已经为包含 p12 文件的文件夹设置了完全权限。

有人可以帮忙吗?

可能的欺骗,并且有一个可能的答案:

"发生内部错误。" 使用 X509Certificate2 加载 pfx 文件时

简而言之,在您的本地环境中,它可能会尝试将证书放在本地用户存储中,但无法从您的网站访问该存储。 相反,需要告诉它去机器商店。

相关内容

最新更新