Table of Contents

Class X509CertificateLoader

Namespace
Arc4u.Security.Cryptography
Assembly
Arc4u.dll

The default IX509CertificateLoader: it searches the certificate stores of the machine or loads PEM files.

[Export(typeof(IX509CertificateLoader))]
public class X509CertificateLoader : IX509CertificateLoader
Inheritance
X509CertificateLoader
Implements
Inherited Members
Extension Methods

Constructors

X509CertificateLoader(ILogger<X509CertificateLoader>?)

Initializes a new instance of the X509CertificateLoader class.

public X509CertificateLoader(ILogger<X509CertificateLoader>? logger)

Parameters

logger ILogger<X509CertificateLoader>

An optional logger used to trace missing files.

Methods

FindCertificate(CertificateFilePathInfo?)

Creates a certificate from PEM files.

public X509Certificate2 FindCertificate(CertificateFilePathInfo? certificateFilePathInfo)

Parameters

certificateFilePathInfo CertificateFilePathInfo

Returns

X509Certificate2

The certificate, with its private key.

Exceptions

ArgumentNullException

certificateFilePathInfo is null.

FileNotFoundException

The public certificate file or the private key file does not exist.

FindCertificate(CertificateInfo)

Just a wrapper class to encapsultate the search of a certificate in the system based on the OS.

public X509Certificate2 FindCertificate(CertificateInfo certificateInfo)

Parameters

certificateInfo CertificateInfo

Returns

X509Certificate2

FindCertificate(IConfiguration, string)

Read the current section and identify if the section contains a CertificateStore entry. If yes, the Certificate will be retrieve based on the CertificateInfo object. If no CertificateStore section exists, the File is checked and a certificate will be created bqsed on the pem files (private and public keys).

public X509Certificate2? FindCertificate(IConfiguration configuration, string sectionName)

Parameters

configuration IConfiguration

IConfiguration

sectionName string

The name of the section if the IConfiguration

Returns

X509Certificate2

FindCertificate(string, X509FindType, StoreLocation, StoreName)

Find a certificate in the system: Certificate store for Windows or Keychain...

protected X509Certificate2 FindCertificate(string find, X509FindType findType = X509FindType.FindBySubjectName, StoreLocation location = StoreLocation.LocalMachine, StoreName name = StoreName.My)

Parameters

find string

The certificate criteria to look for...

findType X509FindType

X509FindType, default is FindBySubjectName

location StoreLocation

StoreLocation, default is LocalMachine

name StoreName

StoreName, default is My

Returns

X509Certificate2

The X509Certificate2

Exceptions

KeyNotFoundException

No certificate is found!