Export X509Certificate2 to byte array with the Private key
The Export function of the X509Certificate2 class allows you to export a certificate with the private key to a byte array. The following code demonstrates exporting a certificate with the private key: X509Store store = new X509Store(StoreLocation.CurrentUser); store.Open(OpenFlags.ReadOnly); X509Certificate2 cert = store.Certificates[1]; // Export the certificate including the private key. byte[] certBytes = cert.Export(X509ContentType.Pkcs12); To … Read more