Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to read X509 Signing Certificate content from string in .net?

I have X509 Signing Certificate inside of a string like:

var signingCertificate = -----BEGIN CERTIFICATE-----\r\nMIICTjCCAbegAw.........-----END CERTIFICATE-----

Now I want to read the content of this certificate. i know we can do it using X509Certificate2 object but that reads from file directly. Is there anyway to read the content from string?

like image 834
Ask Avatar asked Oct 23 '25 09:10

Ask


1 Answers

You can convert your string to byte array, and create a X509Certificate2 object from it.

byte[] bytes = Encoding.ASCII.GetBytes(signingCertificate);
var x509Certificate2 = new X509Certificate2(bytes);
like image 163
Amadej Kastelic Avatar answered Oct 25 '25 05:10

Amadej Kastelic



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!