Here is the scenario:
I have several .pfx files and I need to store them in a MySQL DB.
I already tried to store the RawData thing, but when I try to sign a xml using the reconstructed certificate I get:
Signing key is not loaded.
Well so I tried to store the private key, using the function ToXmlString to generate a string from the private key and FromXmlString to load the new string, but then I get:
Object contains only the public half of a key pair. A private key must also be provided.
The point is, how to correctly store the certificate and its keys in the DB in a way that I can reconstruct it and use it for digital signing documents?
Update:
Already tried this and didn’t work:
Store an X509Certificate2 in DB
The certificate only includes the public key, so storing only that won’t work.
On the other hand,
cert.PrivateKey.ToXmlString(true)should work. Are you sure that you remembered to call it with theincludePrivateParametersargument set to true and that you imported it as exportable?Alternatively, you could just store the entire pfx in the database.