相关疑难解决方法(0)

从字符串创建X509Certificate2时"无法找到请求的对象"异常

我想X509Certificate2从字符串创建.让我举个例子:

string keyBase64String = Convert.ToBase64String(file.PKCS7);
var cert = new X509Certificate2(Convert.FromBase64String(keyBase64String));
Run Code Online (Sandbox Code Playgroud)

keyBase64String有这样的内容:"MIIF0QYJKoZI ........hvcNAQcCoIIFwjCCBb4CA0="

并且file.PKCS7我从数据库下载的字节数组.

创建时我遇到以下异常X509Certificate2:

找不到请求的对象

并且堆栈跟踪:

"无法在系统中的System.Security.Cryptography.X509Certificates.X509Utils._QueryCertBlobType(Byte [] rawData)处的System.Security.Cryptography.CryptographicException.ThrowCryptographicException(Int32hr)中找不到请求的对象"X509Certificate2异常"无法找到请求的对象"}. WebApp.SoupController.d__7.MoveNext()上的System.Security.Cryptography.X509Certificates.X509Certificate2..ctor(Byte [] rawData)中的Security.Cryptography.X509Certificates.X509Certificate.LoadCertificateFromBlob(Byte [] rawData,Object password,X509KeyStorageFlags keyStorageFlags)在D:\ Projects\WebApp\Controllers\SoupController.cs中:第118行

请告诉我我做错了什么.任何帮助将不胜感激!

c# encryption x509certificate2 public-key-encryption

9
推荐指数
1
解决办法
1万
查看次数