<PackageReference Include="BouncyCastle.Cryptography" Version="2.7.0" />

Org.BouncyCastle.Pkcs.Pkcs12Store

public class Pkcs12Store
In-memory PKCS#12 keystore (PFX) as defined in RFC 7292. Loads and saves password-protected bags of private keys and X.509 certificates. Create instances via Pkcs12StoreBuilder.
public const string IgnoreUselessPasswordProperty = "Org.BouncyCastle.Pkcs12.IgnoreUselessPassword"

Environment variable that, when set to true, suppresses the error raised when Load is called with a password but the file does not require one.

public IEnumerable<string> Aliases { get; }

Gets all aliases in this store (union of certificate and key aliases).

public int Count { get; }

Gets the number of distinct aliases in this store.

public bool ContainsAlias(string alias)

Returns true if an entry exists under the given alias.

public void DeleteEntry(string alias)

Removes the entry (certificate and/or key) for the given alias.

public X509CertificateEntry GetCertificate(string alias)

Returns the certificate entry for the alias — either a certificate-only entry or the end-entity certificate associated with a private-key alias.

Finds the alias of the first entry whose certificate equals cert.

Builds the certificate chain for a private-key alias by following Authority Key Identifier or issuer/subject matching.

public AsymmetricKeyEntry GetKey(string alias)

Returns the private-key entry for the given alias, or null if not present.

public bool IsCertificateEntry(string alias)

Returns true if the alias refers to a certificate-only entry (no private key).

public bool IsEntryOfType(string alias, Type entryType)

Returns true if the alias refers to an entry assignable to entryType.

public bool IsKeyEntry(string alias)

Returns true if the alias refers to a private-key entry.

public void Load(Stream input, char[] password)

Loads a PKCS#12 file from a stream, populating this store with keys and certificates.

protected virtual void LoadKeyBag(PrivateKeyInfo privKeyInfo, Asn1Set bagAttributes, ref AsymmetricKeyEntry unmarkedKeyEntry)

protected virtual void LoadPkcs8ShroudedKeyBag(EncryptedPrivateKeyInfo encPrivKeyInfo, Asn1Set bagAttributes, char[] password, bool wrongPkcs12Zero, ref AsymmetricKeyEntry unmarkedKeyEntry)

public void Save(Stream stream, char[] password, SecureRandom random)

Writes this store as a PKCS#12 PFX structure to a stream.

public void SetCertificateEntry(string alias, X509CertificateEntry certEntry)

Adds or replaces a certificate-only entry under the given alias.

public void SetFriendlyName(string alias, string newFriendlyName)

Renames an entry by updating its PKCS#9 friendly name and re-keying internal maps.

public void SetKeyEntry(string alias, AsymmetricKeyEntry keyEntry, X509CertificateEntry[] chain)

Adds or replaces a private-key entry and optional certificate chain under the given alias.