Skip to content

CertificateLoader.LoadFromStoreCert(string, string, StoreLocation, bool, bool)

LoadFromStoreCert(string, string, StoreLocation, bool, bool)

static
View source
public static X509Certificate2 LoadFromStoreCert(string subject, string storeName, StoreLocation storeLocation, bool allowInvalid, bool server)
Loads the newest matching certificate which has an accessible private key and is valid for the requested TLS role.

Parameters

subjectstring
The subject name to search for.
storeNamestring
The name of the certificate store.
storeLocationStoreLocation
The location of the certificate store.
allowInvalidbool
true to include certificates which do not pass certificate-chain validation; otherwise, false.
serverbool
true to select a certificate valid for server authentication; false to select one valid for client authentication.

Returns

The selected certificate.

Exceptions

System.InvalidOperationException
No suitable certificate was found.