I'm working with X509 certificates and have a MyCert.pfx file that contains the certificate and both public and private keys. It happens that I exported this certificate from a certificate store on my local machine.
My goal is to pretend I'm on a different machine and read the PFX file and make a new X509Certificate2 from the data and password that I have.
I can do that successfully on my own machine as long as I add the UserKeySet
flag to the constructor call.
var flags = X509KeyStorageFlags.UserKeySet;
var cert = new X509Certificate2(certKeyData, certPwd, flags);
What bothers me is that my constructor call fails ("Access denied.") without the UserKeySet
flag. I know I need the flag to point to my local (personal) certificates in the machine store, but the real question is why the constructor is looking into my personal or machine key stores at all. I'm trying to pretend I'm on a different machine that has no such store.
Q. Should I be able to create an X509Certificate2 WITHOUT looking in a store on my local machine? If not, why not? Isn't the certificate just a pile of bytes that is unrelated to any key store on any particular machine? Can they exist without reference to, or accessing, a local store? Thank you.