我正在尝试从字符串创建X509Certificate2
。让我举个例子:
string keyBase64String = Convert.ToBase64String(file.PKCS7);
var cert = new X509Certificate2(Convert.FromBase64String(keyBase64String));
而keyBase64String
具有如下内容:"MIIF0QYJKoZI ........hvcNAQcCoIIFwjCCBb4CA0="
file.PKCS7
是我从数据库中下载的字节数组。
在创建X509Certificate2
时,我遇到了以下异常:
找不到请求的对象
以下是堆栈跟踪:
"Cannot find requested object" X509Certificate2 Exception "Cannot find requested object"} at System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 hr) at System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte[] rawData) at System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte[] rawData, Object password, X509KeyStorageFlags keyStorageFlags) at System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte[] rawData) at WebApp.SoupController.d__7.MoveNext() in D:\Projects\WebApp\Controllers\SoupController.cs:line 118
请告诉我我的错误在哪里。任何帮助都将不胜感激!