【发布时间】:2017-10-18 14:28:00
【问题描述】:
我正在尝试从字符串创建X509Certificate2。让我举个例子:
string keyBase64String = Convert.ToBase64String(file.PKCS7);
var cert = new X509Certificate2(Convert.FromBase64String(keyBase64String));
而keyBase64String有这样一个内容:"MIIF0QYJKoZI ........hvcNAQcCoIIFwjCCBb4CA0="
而file.PKCS7 是我从数据库中下载的字节数组。
创建X509Certificate2时出现以下异常:
找不到请求的对象
还有堆栈跟踪:
“找不到请求的对象”X509Certificate2 异常“找不到 请求的对象”} 在 System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32 小时)在 System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(字节[] 原始数据)在 System.Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(字节[] rawData,对象密码,X509KeyStorageFlags keyStorageFlags)在 System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(字节 [] 原始数据)在 WebApp.SoupController.d__7.MoveNext() 在 D:\Projects\WebApp\Controllers\SoupController.cs:line 118
请告诉我我做错了什么。任何帮助将不胜感激!
【问题讨论】:
-
您尝试使用构造函数加载的数据实际上是 PKCS7 格式吗?您的命名表明
-
@mat 它是一个证书,但它存储为字节数组。
-
普通的 X.509 证书?那你为什么叫它PKCS7呢?
标签: c# encryption public-key-encryption x509certificate2