On Win Server 2008, I can execute the code below, and when I try to export the cert via the MMC GUI, I do not have the option to export the private key as well. However, if I use the GUI to import the cert, I am allowed to export the private key also. What am I missing in my code?
string certfile = @"mycert.p12";
SecureString secString = new SecureString();
foreach (char c in "password")
{
secString.AppendChar(c);
}
X509Certificate2 cert = new X509Certificate2(certfile, secString, X509KeyStorageFlags.Exportable);
var store = new X509Store(StoreName.My , StoreLocation.CurrentUser);
store.Add(cert);
Aha. The key storage flags should be Exportable and persisted.
X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With