X509Certificate Constructor Exception

后端 未结 9 1864
梦如初夏
梦如初夏 2020-11-27 15:38
//cert is an EF Entity and 
//    cert.CertificatePKCS12 is a byte[] with the certificate.

var certificate = new X509Certificate(cert.CertificatePKCS12, \"SomePassw         


        
9条回答
  •  囚心锁ツ
    2020-11-27 16:22

    To be able really solve your problem and not just guess, what can it be, one need be able to reproduce your problem. If you can't provide test PFX file which have the same problem you have to examine the problem yourself. The first important question is: are the origin of the exception "An internal error occurred" in the private key part of the PKCS12 or in the public part of the certificate itself?

    So I would recommend you to try to repeat the same experiment with the same certificate, exported without private key (like .CER file):

    var certificate = new X509Certificate(cert.CertificateCER);
    

    or

    var certificate = new X509Certificate.CreateFromCertFile("My.cer");
    

    It could help to verify whether the origin of your problem is the private key or some properties of the certificate.

    If you will have problem with the CER file you can safe post the link to the file because it have public information only. Alternatively you can at least execute

    CertUtil.exe -dump -v "My.cer"
    

    or

    CertUtil.exe -dump -v -privatekey -p SomePassword "My.pfx"
    

    (you can use some other options too) and post some parts of the output (for example properties of the private key without the PRIVATEKEYBLOB itself).

提交回复
热议问题