I have an X509Certificate2 certificate in my store that I would like to export to a byte array with the private key. 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.
I have tried many wayes but has not succeded to export the certificate with the private key.
X509Store store = new X509Store(StoreLocation.CurrentUser);
store.Open(OpenFlags.ReadOnly);
X509Certificate2 cert = store.Certificates[1];
byte[] certBytes = cert.GetRawCertData(); // Obviously does not work!
Is it possible to successfully export the certificate with private key to a byte array?
Help is very appreciated.