Search code examples
.netx509x509certificate2

How do I use X509Certificate2 for mutual SSL in .NET? Private key is not recognized


So, I have a private key, and a certificate in 2 files... I need to feed that to X509Certificate2 to use for mutual SSL. When I simply do new X509Certificate2 - I can specify one file name. I created .pem file with both, but cert.HasPrivateKey shows FALSE.

What would be the format in which both will be in one file, and X509Certificate2 would understand?


Solution

  • A p12/pkcs12/pfx file has both private key and certificate

    An example of using this is:

    X509Certificate2 cert = X509Certificate2(@"C:\Path\my.pfx", "password");