DEV Community

Cover image for Loading Certificates on .NET 9
Andreas Nägeli
Andreas Nägeli

Posted on

1

Loading Certificates on .NET 9

I've seen a lot of traffic regarding the X509CertificateLoader on my website lately, so I guess people are struggling with fixing the deprecations on the constructor of X509Certificate2 (as I did, too).

So basically:

// from file
var cert = new X509Certificate2("./myfile.pfx");

// from byte array
var stream = new MemoryStream();
var cert = new X509Certificate2(stream.ToArray());
Enter fullscreen mode Exit fullscreen mode

has become:

// from file
var cert = X509CertificateLoader.LoadCertificateFromFile("./myfile.pfx");

// from byte array
var stream = new MemoryStream();
var cert = X509CertificateLoader.LoadPkcs12(mem.ToArray(), null);
Enter fullscreen mode Exit fullscreen mode

There are of course more overloads, but you will get the idea.

Cover picture by Marjan Blan

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay