title: Export X509Certificate2 to byte array with the Private key
body: <p>I have an X509Certificate2 certificate in my store that I would like to export to a byte array <strong>with</strong> the <strong>private key</strong>. The certificate byte array has to be so that when I then later would import the certificate from the byte array the private key would have the private key with it.</p>
  
  <p>I have tried many wayes but has not succeded to export the certificate with the <strong>private key</strong>.</p>
  
  <pre><code>X509Store store = new X509Store(StoreLocation.CurrentUser);      
  
  store.Open(OpenFlags.ReadOnly);
  
  X509Certificate2 cert = store.Certificates[1];
  
  byte[] certBytes = cert.GetRawCertData(); // Obviously does not work!
  </code></pre>
  
  <p>Is it possible to successfully export the certificate with private key to a byte array?</p>
  
  <p>Help is very appreciated.</p>