相关疑难解决方法(0)

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

我正在尝试使用自签名证书(c#):

X509Certificate2 cert = new X509Certificate2(
    Server.MapPath("~/App_Data/myhost.pfx"), "pass");
Run Code Online (Sandbox Code Playgroud)

在共享的Web托管服务器上,我收到一个错误:

System.Security.Cryptography.CryptographicException: An internal error occurred.
Run Code Online (Sandbox Code Playgroud)

堆栈跟踪结束

System.Security.Cryptography.CryptographicException.
    ThrowCryptogaphicException(Int32 hr) +33
System.Security.Cryptography.X509Certificates.X509Utils.
    _LoadCertFromFile(String fileName, IntPtr password, UInt32 dwFlags, 
        Boolean persistKeySet, SafeCertContextHandle& pCertCtx) +0
System.Security.Cryptography.X509Certificates.X509Certificate.
    LoadCertificateFromFile(String fileName, Object password, 
        X509KeyStorageFlags keyStorageFlags) +237
System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(
    String fileName, String password) +131
Run Code Online (Sandbox Code Playgroud)

在我的开发机器上,它加载正常.我加载*.pfx而不是*.cer文件的原因是因为我需要私钥访问(cer文件加载好).我在我的dev mochine上制作了pfx:

makecert -r -n "CN=myhost.com, E=admin@myhost.com" -sky exchange -b 01/01/2009
    -pe -sv myhost.pvk myhost.cer
<b>pvk2pfx</b> -pvk myhost.pvk -spc myhost.cer -pfx myhost.pfx -po pass</code>
Run Code Online (Sandbox Code Playgroud)

我使用的是makecert的v5.131.3790.0版本

c# pfx x509certificate

77
推荐指数
2
解决办法
5万
查看次数

X509Certificate构造函数异常

//cert is an EF Entity and 
//    cert.CertificatePKCS12 is a byte[] with the certificate.

var certificate = new X509Certificate(cert.CertificatePKCS12, "SomePassword");
Run Code Online (Sandbox Code Playgroud)

从我们的数据库加载证书时,在我们的登台服务器(Windows 2008 R2/IIS7.5)上,我们遇到以下异常:

System.Security.Cryptography.CryptographicException: An internal error occurred.

   at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr)
   at System.Security.Cryptography.X509Certificates.X509Utils._LoadCertFromBlob(Byte[] rawData, IntPtr password, UInt32 dwFlags, Boolean persistKeySet, SafeCertContextHandle& pCertCtx)
   at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags)
Run Code Online (Sandbox Code Playgroud)

注意:此问题不会在本地发生(Windows 7/Casini).

非常感谢任何见解.

.net c# x509certificate

68
推荐指数
4
解决办法
4万
查看次数

标签 统计

c# ×2

x509certificate ×2

.net ×1

pfx ×1