Associate A Private Key With The X509Certificate2 Class In .net
Answer : You can save yourself the hassle of copy-pasting all that code and store the private key next to the certificate in a pfx / pkcs#12 file: openssl pkcs12 -export -in my.cer -inkey my.key -out mycert.pfx You'll have to supply a password, which you have to pass to the constructor of X509Certificate2 : X509Certificate2 cert = new X509Certificate2("mycert.pfx","password"); For everyone else with the same problem, I found a neat little piece of code that let's you do exactly that: http://www.codeproject.com/Articles/162194/Certificates-to-DB-and-Back byte[] certBuffer = Helpers.GetBytesFromPEM(publicCert, PemStringType.Certificate); byte[] keyBuffer = Helpers.GetBytesFromPEM(privateKey, PemStringType.RsaPrivateKey); X509Certificate2 certificate = new X509Certificate2(certBuffer, password); RSACryptoServiceProvider prov = Crypto.DecodeRsaPrivateKey(keyBuffer); certificate.PrivateKey = prov; EDIT: The code for the Helper method (which ot...