Edit

Share via


X509CertificateLoader.LoadPkcs12 Method

Definition

Overloads

LoadPkcs12(Byte[], String, X509KeyStorageFlags, Pkcs12LoaderLimits)

Loads the provided data as a PKCS#12 PFX and extracts a certificate.

LoadPkcs12(ReadOnlySpan<Byte>, ReadOnlySpan<Char>, X509KeyStorageFlags, Pkcs12LoaderLimits)

Loads the provided data as a PKCS#12 PFX and extracts a certificate.

LoadPkcs12(Byte[], String, X509KeyStorageFlags, Pkcs12LoaderLimits)

Source:
X509CertificateLoader.cs
Source:
X509CertificateLoader.cs

Loads the provided data as a PKCS#12 PFX and extracts a certificate.

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

Parameters

data
Byte[]

The data to load.

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

data 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.

Remarks

A PKCS#12/PFX can contain multiple certificates. Using the ordering that the certificates appear in the results of LoadPkcs12Collection(ReadOnlySpan<Byte>, 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

LoadPkcs12(ReadOnlySpan<Byte>, ReadOnlySpan<Char>, X509KeyStorageFlags, Pkcs12LoaderLimits)

Source:
X509CertificateLoader.cs
Source:
X509CertificateLoader.cs

Loads the provided data as a PKCS#12 PFX and extracts a certificate.

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

Parameters

data
ReadOnlySpan<Byte>

The data to load.

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

data 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.

Remarks

A PKCS#12/PFX can contain multiple certificates. Using the ordering that the certificates appear in the results of LoadPkcs12Collection(Byte[], 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