Jaahas.CertificateUtilities
1.0.0
See the version list below for details.
dotnet add package Jaahas.CertificateUtilities --version 1.0.0
NuGet\Install-Package Jaahas.CertificateUtilities -Version 1.0.0
<PackageReference Include="Jaahas.CertificateUtilities" Version="1.0.0" />
paket add Jaahas.CertificateUtilities --version 1.0.0
#r "nuget: Jaahas.CertificateUtilities, 1.0.0"
// Install Jaahas.CertificateUtilities as a Cake Addin #addin nuget:?package=Jaahas.CertificateUtilities&version=1.0.0 // Install Jaahas.CertificateUtilities as a Cake Tool #tool nuget:?package=Jaahas.CertificateUtilities&version=1.0.0
Jaahas.CertificateUtilties
This package provides a set of utilities for working with X.509 certificates.
Installation
Add a NuGet package reference to Jaahas.CertificateUtilities.
Getting Started
The package contains assemblies for both .NET Framework 4.7.2 and .NET 8.0. Some functionality is only available in the .NET 8.0 version.
Certificate Loader
The CertificateLoader
class provides a simple way to load client or server certificates from the file system or from the Windows certificate store. It is largely based on Kestrel's internal certificate loader.
var loader = new CertificateLoader();
var certificateFromStore = loader.LoadCertificate(new CertificateLocation() {
Subject = "MyCertificate",
Store = "My",
Location = "CurrentUser"
}, enhancedKeyUsage: CertificateLoader.ServerAuthenticationOid);
var certificateFromFile = loader.LoadCertificate(new CertificateLocation() {
Path = @"C:\path\to\certificate.pfx",
Password = "<PFX password>"
});
When loading a certificate from a certificate store you can also specify if expired or invalid certificates can be returned, and whether or not the private key for the certificate must also be available. By default, expired or invalid certificates are not returned and the private key is required.
var location = new CertificateLocation() {
Subject = "MyCertificate",
Store = "My",
Location = "CurrentUser",
AllowInvalid = true,
RequirePrivateKey = false
};
You can also create a CertificateLocation
instance from a path to a certificate file or certificate store location using the static CertificateLocation.CreateFromPath
method. The method will parse your path to determine if it is a file system path or a certificate store path:
// Create from file path
var location1 = CertificateLocation.CreateFromPath(@"C:\path\to\certificate.pfx");
// Create from certificate store location
var location2 = CertificateLocation.CreateFromPath(@"cert:\CurrentUser\My\localhost");
Certificate store locations can be specified using the format cert:\{location}\{store}\{subject_or_thumbprint_or_distinguished_name}
. The format is case-insensitive and can use both back- and forward-slashes as path separators.
When creating a CertificateLocation
using CreateFromPath
, remember that you may still need to set properties such as Password
or KeyPath
separately.
On .NET 8.0 and higher, it is also possible to load certificates and private keys from separate PEM-encoded files:
var loader = new CertificateLoader();
var certificate = loader.LoadCertificate(new CertificateLocation() {
Path = @"C:\path\to\certificate.pem",
KeyPath = @"C:\path\to\private-key.pem",
Password = "<private key password>"
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Framework | net472 is compatible. net48 was computed. net481 was computed. |
-
.NETFramework 4.7.2
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
-
net8.0
- Microsoft.Extensions.Logging.Abstractions (>= 8.0.1)
- System.ComponentModel.Annotations (>= 5.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.