【问题标题】:Cannot read p12 file on windows server 2008无法在 windows server 2008 上读取 p12 文件
【发布时间】:2017-12-30 06:01:22
【问题描述】:

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

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

在 System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 小时)在 System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromFile(字符串 fileName, IntPtr 密码, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle & pCertCtx) 在 System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromFile(字符串 文件名,对象密码,X509KeyStorageFlags keyStorageFlags)在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字符串 文件名、字符串密码、X509KeyStorageFlags keyStorageFlags)

我的代码是:

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

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

有人可以帮忙吗?

【问题讨论】:

  • 九 对不起,我更改了路径以显示代码更简单,我会更新这个,但这不是问题,谢谢
  • 您是否尝试过以管理员权限运行应用程序?
  • 这在一个网站上发布在 IIS 上,使用 AppPoolIdentity 运行,其他具有相同身份的应用程序工作正常

标签: c# ssl-certificate windows-server-2008


【解决方案1】:

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

"An internal error occurred." when loading pfx file with X509Certificate2

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

【讨论】:

  • 谢谢Alan,检查一下……但我不想安装p12,你知道这是否需要吗?
  • AFAIK,所有 X509Certificate2 构造函数都将证书存储在容器中 - 因此,如果您不希望它进入用户容器,则需要进入本地计算机容器。如果您真的不希望它持久存在,您可能需要在完成后将其从商店中删除。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-11-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多