Class PKCS12KeyStoreSpi

java.lang.Object
java.security.KeyStoreSpi
org.bouncycastle.jcajce.provider.keystore.pkcs12.PKCS12KeyStoreSpi
All Implemented Interfaces:
PKCSObjectIdentifiers, X509ObjectIdentifiers, BCKeyStore

public class PKCS12KeyStoreSpi extends KeyStoreSpi implements PKCSObjectIdentifiers, X509ObjectIdentifiers, BCKeyStore
BC's JCA-visible KeyStoreSpi for the PKCS#12 keystore family (provider "BC", types PKCS12, PKCS12-DEF, PKCS12-3DES-40RC2, PKCS12-3DES-3DES, PKCS12-AES256-AES128 and the -DEF- aliases).

Supported entry types

  • Private-key entriesKeyStore.PrivateKeyEntry with a non-empty certificate chain. Stored as a SafeBag of type pkcs8ShroudedKeyBag per RFC 7292 sec. 4.2.2, with the associated chain emitted as certBag entries.
  • Trusted-certificate entriesKeyStore.TrustedCertificateEntry. Stored as a certBag per RFC 7292 sec. 4.2.3.
  • Secret-key entriesKeyStore.SecretKeyEntry, accepted since Bouncy Castle 1.85 (github #1807). Stored as a SafeBag of type secretBag per RFC 7292 sec. 4.2.5: the inner SecretBag carries the algorithm OID as secretTypeId and the SecretKey.getEncoded() bytes as a DER OCTET STRING secretValue, placed inside the keystore's encrypted SafeContents block. Only algorithms with a registered OID are supported — see PKCS12Util.resolveSecretKeyOid(SecretKey) for the current set (AES 128 / 192 / 256, DESede / TripleDES, HmacSHA1 / SHA-224 / SHA-256 / SHA-384 / SHA-512 / SHA3-{224,256,384,512}). Other algorithms are rejected at setKeyEntry-time with a pointer at BCFKS.

SunJCE secret-key interop (read-only, opt-in)

SunJCE writes secret keys using a non-standard encoding: the SafeBag is still secretBag, but the inner SecretBag.secretTypeId is pkcs8ShroudedKeyBag and the secretValue wraps an EncryptedPrivateKeyInfo whose decrypted PKCS#8 carries the raw key bytes. Setting the system or security property Properties.PKCS12_ALLOW_SUN_SECRET_KEYS ("org.bouncycastle.pkcs12.allow_sun_secret_keys") to true lets BC additionally decode this form on load. BC always writes the standards-compliant form regardless — i.e. files BC produces are not readable by SunJCE's PKCS#12 keystore.

System / security properties consulted

See Also: