Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Load X509 certificate from disk .Net Core

I've created an X509 certificate using OpenSSL. I am trying to load it using the Import method on the X509Certificate2 class, in .NET Core 2.0.

var cert = new X509Certificate2();
cert.Import(_path);

But get thrown the following exception:

System.PlatformNotSupportedException : X509Certificate is immutable on this 
platform. Use the equivalent constructor instead.

Which constructor should I be using / what is the correct way to load this certificate from disk?

like image 537
BlackSpy Avatar asked Dec 11 '17 15:12

BlackSpy


1 Answers

You can use

var x509 = new X509Certificate2(File.ReadAllBytes(_path));
like image 83
Ivan Zaruba Avatar answered Sep 30 '22 05:09

Ivan Zaruba