I am trying to create X509Certificate2from a string. Let me show you an example:
string keyBase64String = Convert.ToBase64String(file.PKCS7);
var cert = new X509Certificate2(Convert.FromBase64String(keyBase64String));
and keyBase64Stringhas the following content:"MIIF0QYJKoZI ........hvcNAQcCoIIFwjCCBb4CA0="
and file.PKCS7- this is a byte array that I loaded from the database.
I have the following exception when creating X509Certificate2:
Unable to find the requested object
And the stack trace:
"Cannot find the requested object" X509Certificate2 Exception "Cannot find the requested object"} in System.Security.Cryptography.CryptographicException.ThrowCryptographicException (Int32 h) in System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType (bytes) System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob (byte [] rawData, password of the object, X509KeyStorageFlags keyStorageFlags) on System.Security.Cryptography.X509Certificates.X509Certificate2..ctor.D__. [Byte] () in D: \ Projects \ WebApp \ Controllers \ SoupController.cs: line 118
Please tell me what I am doing wrong. Any help would be greatly appreciated!