Redigera

Dela via


X509CertificateLoader.LoadPkcs12FromFile Method

Definition

Overloads

LoadPkcs12FromFile(String, ReadOnlySpan<Char>, X509KeyStorageFlags, Pkcs12LoaderLimits)

Opens the specified file, reads the contents as a PKCS#12 PFX and extracts a certificate.

LoadPkcs12FromFile(String, String, X509KeyStorageFlags, Pkcs12LoaderLimits)

Opens the specified file, reads the contents as a PKCS#12 PFX and extracts a certificate.

LoadPkcs12FromFile(String, ReadOnlySpan<Char>, X509KeyStorageFlags, Pkcs12LoaderLimits)

Source:
X509CertificateLoader.cs
Source:
X509CertificateLoader.cs

Opens the specified file, reads the contents as a PKCS#12 PFX and extracts a certificate.

public static System.Security.Cryptography.X509Certificates.X509Certificate2 LoadPkcs12FromFile (string path, ReadOnlySpan<char> password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet, System.Security.Cryptography.X509Certificates.Pkcs12LoaderLimits? loaderLimits = default);
static member LoadPkcs12FromFile : string * ReadOnlySpan<char> * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags * System.Security.Cryptography.X509Certificates.Pkcs12LoaderLimits -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Shared Function LoadPkcs12FromFile (path As String, password As ReadOnlySpan(Of Char), Optional keyStorageFlags As X509KeyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet, Optional loaderLimits As Pkcs12LoaderLimits = Nothing) As X509Certificate2

Parameters

path
String

The path of the file to open.

password
ReadOnlySpan<Char>

The password to decrypt the contents of the PFX.

keyStorageFlags
X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the private key associated with the returned certificate.

loaderLimits
Pkcs12LoaderLimits

Limits to apply when loading the PFX. A null value, the default, is equivalent to Defaults.

Returns

The loaded certificate.

Exceptions

path is null.

keyStorageFlags contains a value, or combination of values, that is not valid.

keyStorageFlags contains a value that is not valid for the current platform.

The PKCS#12/PFX violated one or more constraints of loaderLimits.

An error occurred while loading the PKCS#12/PFX.

An error occurred while loading the specified file.

Remarks

A PKCS#12/PFX can contain multiple certificates. Using the ordering that the certificates appear in the results of LoadPkcs12CollectionFromFile(String, ReadOnlySpan<Char>, X509KeyStorageFlags, Pkcs12LoaderLimits), this method returns the first certificate where HasPrivateKey is true. If no certificates have associated private keys, then the first certificate is returned. If the PKCS#12/PFX contains no certificates, a CryptographicException is thrown.

Applies to

LoadPkcs12FromFile(String, String, X509KeyStorageFlags, Pkcs12LoaderLimits)

Source:
X509CertificateLoader.cs
Source:
X509CertificateLoader.cs

Opens the specified file, reads the contents as a PKCS#12 PFX and extracts a certificate.

public static System.Security.Cryptography.X509Certificates.X509Certificate2 LoadPkcs12FromFile (string path, string? password, System.Security.Cryptography.X509Certificates.X509KeyStorageFlags keyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet, System.Security.Cryptography.X509Certificates.Pkcs12LoaderLimits? loaderLimits = default);
static member LoadPkcs12FromFile : string * string * System.Security.Cryptography.X509Certificates.X509KeyStorageFlags * System.Security.Cryptography.X509Certificates.Pkcs12LoaderLimits -> System.Security.Cryptography.X509Certificates.X509Certificate2
Public Shared Function LoadPkcs12FromFile (path As String, password As String, Optional keyStorageFlags As X509KeyStorageFlags = System.Security.Cryptography.X509Certificates.X509KeyStorageFlags.DefaultKeySet, Optional loaderLimits As Pkcs12LoaderLimits = Nothing) As X509Certificate2

Parameters

path
String

The path of the file to open.

password
String

The password to decrypt the contents of the PFX.

keyStorageFlags
X509KeyStorageFlags

A bitwise combination of the enumeration values that control where and how to import the private key associated with the returned certificate.

loaderLimits
Pkcs12LoaderLimits

Limits to apply when loading the PFX. A null value, the default, is equivalent to Defaults.

Returns

The loaded certificate.

Exceptions

path is null.

keyStorageFlags contains a value, or combination of values, that is not valid.

keyStorageFlags contains a value that is not valid for the current platform.

The PKCS#12/PFX violated one or more constraints of loaderLimits.

An error occurred while loading the PKCS#12/PFX.

An error occurred while loading the specified file.

Remarks

A PKCS#12/PFX can contain multiple certificates. Using the ordering that the certificates appear in the results of LoadPkcs12CollectionFromFile(String, String, X509KeyStorageFlags, Pkcs12LoaderLimits), this method returns the first certificate where HasPrivateKey is true. If no certificates have associated private keys, then the first certificate is returned. If the PKCS#12/PFX contains no certificates, a CryptographicException is thrown.

Applies to