X509Certficate2 - 无法使用字节数组创建

X509Certficate2 - 无法使用字节数组创建

我是 ASP 新手,我在 html 页面中使用 csharp。这是我的代码,clientcert 是一个 base64 编码的证书。我可以将其打印在屏幕上。我还可以将打印到屏幕上并知道它是 byte[] 类型。但是,当我执行以下操作时,会出现错误。

<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Security.Cryptography.X509Certificates" %>
<%@ Import Namespace="System.Text" %>
<%@ Page Language="c#"%>


<%
string certPem = Request.Headers["ClientCert"];
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] a = encoding.GetBytes(certPem);
X509Certificate2 cer = new X509Certificate2(a);
%>

[CryptographicException: Cannot find the requested object.
]
Exception Details: System.Security.Cryptography.CryptographicException: 
Cannot find the requested object.

我想知道,为什么我可以正常获取 x509 对象——当执行 new x509Certificate2(); 时它可以工作,没有任何参数,但是当传递一个字节数组时它就会出错。

相关内容