DEV Community

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

Posted on

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)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay