X509Certficate2 - Cannot Create with Byte Array

I'm new to ASP and I'm using csharp inside my html page. This is my code, clientcert is a base64 encoded cert. I can print that out on the screen fine. I can also print out a to the screen and know it's of type byte[]. However I get an error when I do the following.

<%@ 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.

I'm wondering, why can I get a x509 object fine -- it works when doing new x509Certificate2(); with no arguments, but when passing it a byte array it just errors out.

1 Reset to default

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like