Load X509 certificate from disk .Net Core

22,482

You can use

var x509 = new X509Certificate2(File.ReadAllBytes(_path));
Share:
22,482

Related videos on Youtube

BlackSpy
Author by

BlackSpy

Updated on July 09, 2022

Comments

  • BlackSpy
    BlackSpy almost 2 years

    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?

    • RaniDevpr
      RaniDevpr over 6 years
      Have you tried new X509Certificate2(certificateAsByteArray), looking into the code of .net core import not implemented : github.com/dotnet/corefx/blob/…
  • Ivan Zaruba
    Ivan Zaruba over 3 years
    @user1034912 sorry to hear that. What runtime version do you use? Do you have the private key included in the PFX or is it ephemeral?