title: Create X509Certificate2 from Cert and Key, without making a PFX file
body: <p>In the past I have been making secure TcpListener by exporting a PFX certificate with a password, but would like to know if this step could be skipped. </p>
  
  <p>I'm not using commercial SSL certificates, and have a Root CA, that I use to issue server certificates. These server certificates require additional steps when hosting a TcpListener in C# (I guess because the CSR wasn't used)... but what if I do have the Private Key, and the Certificate that OpenSSL generates/uses.</p>
  
  <pre><code>sslCertificate = new X509Certificate2("myExportedCert.pfx", "1234");
  </code></pre>
  
  <p>So this is great, however I have to issue an openssl command to make a pfx file from the Certificate and the Private Key, then make up some password. Then include this password in my code. </p>
  
  <p>I was wondering if this step was quite necessary. Is there a way to make up a X509Certificate2 from the Cert, and then apply the Private Key. The constructor arguments allow the Cert only part, but encrypting fails then because there is no private key.</p>
  
  <p>Also, I don't want to rely on OpenSSL or IIS to export the pfx.... seems clumsy.</p>
  
  <p>Ideally i would like:</p>
  
  <pre><code>sslCertificate = new X509Certificate2("myCert.crt");
  sslCertificate.ApplyPrivateKey(keyBytes) // &lt;= or "private.key" or whatever
  
  sslStream.AuthenticateAsServer(sslCertificate, false, SslProtocols.Default, false);
  </code></pre>