Top Description Fields Constructors Methods
org.bouncycastle.pkcs

public Class PKCS12PfxPduBuilder

extends Object
Class Inheritance
Imports
java.io.IOException, org.bouncycastle.asn1.ASN1EncodableVector, .ASN1Sequence, .DEROctetString, .DERSequence, .DLSequence, org.bouncycastle.asn1.pkcs.AuthenticatedSafe, .ContentInfo, .MacData, .PKCSObjectIdentifiers, .Pfx, org.bouncycastle.cms.CMSEncryptedDataGenerator, .CMSException, .CMSProcessableByteArray, org.bouncycastle.operator.OutputEncryptor

A builder for the PKCS#12 Pfx key and certificate store.

For example: you can build a basic key store for the user owning privKey as follows:

     X509Certificate[] chain = ....
     PublicKey         pubKey = ....
     PrivateKey        privKey = ....
     JcaX509ExtensionUtils extUtils = new JcaX509ExtensionUtils();

     PKCS12SafeBagBuilder taCertBagBuilder = new JcaPKCS12SafeBagBuilder(chain[2]);

     taCertBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString("Bouncy Primary Certificate"));

     PKCS12SafeBagBuilder caCertBagBuilder = new JcaPKCS12SafeBagBuilder(chain[1]);

     caCertBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString("Bouncy Intermediate Certificate"));

     PKCS12SafeBagBuilder eeCertBagBuilder = new JcaPKCS12SafeBagBuilder(chain[0]);

     eeCertBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString("Eric's Key"));
     eeCertBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_localKeyId, extUtils.createSubjectKeyIdentifier(pubKey));

     PKCS12SafeBagBuilder keyBagBuilder = new JcaPKCS12SafeBagBuilder(privKey, new BcPKCS12PBEOutputEncryptorBuilder(PKCSObjectIdentifiers.pbeWithSHAAnd3_KeyTripleDES_CBC, new CBCBlockCipher(new DESedeEngine())).build(passwd));

     keyBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_friendlyName, new DERBMPString("Eric's Key"));
     keyBagBuilder.addBagAttribute(PKCSObjectIdentifiers.pkcs_9_at_localKeyId, extUtils.createSubjectKeyIdentifier(pubKey));

     //
     // construct the actual key store
     //
     PKCS12PfxPduBuilder pfxPduBuilder = new PKCS12PfxPduBuilder();

     PKCS12SafeBag[] certs = new PKCS12SafeBag[3];

     certs[0] = eeCertBagBuilder.build();
     certs[1] = caCertBagBuilder.build();
     certs[2] = taCertBagBuilder.build();

     pfxPduBuilder.addEncryptedData(new BcPKCS12PBEOutputEncryptorBuilder(PKCSObjectIdentifiers.pbeWithSHAAnd40BitRC2_CBC, new CBCBlockCipher(new RC2Engine())).build(passwd), certs);

     pfxPduBuilder.addData(keyBagBuilder.build());

     PKCS12PfxPdu pfx = pfxPduBuilder.build(new BcPKCS12MacCalculatorBuilder(), passwd);

Field Summary

Modifier and TypeField and Description
private ASN1EncodableVector

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public PKCS12PfxPduBuilder

Returns:

this builder.
addData
(PKCS12SafeBag
the SafeBag to add.
data
)

Add a SafeBag that is to be included as is.

public PKCS12PfxPduBuilder

Returns:

this builder.
addEncryptedData
(OutputEncryptor
the encryptor to use for encoding the data.
dataEncryptor
,
PKCS12SafeBag
the SafeBag to include.
data
)

Add a SafeBag that is to be wrapped in a EncryptedData object.

public PKCS12PfxPduBuilder

Returns:

this builder.
addEncryptedData
(OutputEncryptor
the encryptor to use for encoding the data.
dataEncryptor
,
PKCS12SafeBag[]
the SafeBags to include.
data
)

Add a set of SafeBags that are to be wrapped in a EncryptedData object.

private PKCS12PfxPduBuilder
public PKCS12PfxPdu

Returns:

a Pfx object.
build
(PKCS12MacCalculatorBuilder
a builder for a PKCS12 mac calculator.
macCalcBuilder
,
char[]
the password to use.
password
)

Build the Pfx structure, protecting it with a MAC calculated against the passed in password.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

dataVectorback to summary
private ASN1EncodableVector dataVector

Constructor Detail

PKCS12PfxPduBuilderback to summary
public PKCS12PfxPduBuilder()

Method Detail

addDataback to summary
public PKCS12PfxPduBuilder addData(PKCS12SafeBag data) throws IOException

Add a SafeBag that is to be included as is.

Parameters
data:PKCS12SafeBag

the SafeBag to add.

Returns:PKCS12PfxPduBuilder

this builder.

addEncryptedDataback to summary
public PKCS12PfxPduBuilder addEncryptedData(OutputEncryptor dataEncryptor, PKCS12SafeBag data) throws IOException

Add a SafeBag that is to be wrapped in a EncryptedData object.

Parameters
dataEncryptor:OutputEncryptor

the encryptor to use for encoding the data.

data:PKCS12SafeBag

the SafeBag to include.

Returns:PKCS12PfxPduBuilder

this builder.

Exceptions
IOException:
if a issue occurs processing the data.
addEncryptedDataback to summary
public PKCS12PfxPduBuilder addEncryptedData(OutputEncryptor dataEncryptor, PKCS12SafeBag[] data) throws IOException

Add a set of SafeBags that are to be wrapped in a EncryptedData object.

Parameters
dataEncryptor:OutputEncryptor

the encryptor to use for encoding the data.

data:PKCS12SafeBag[]

the SafeBags to include.

Returns:PKCS12PfxPduBuilder

this builder.

Exceptions
IOException:
if a issue occurs processing the data.
addEncryptedDataback to summary
private PKCS12PfxPduBuilder addEncryptedData(OutputEncryptor dataEncryptor, ASN1Sequence data) throws IOException
buildback to summary
public PKCS12PfxPdu build(PKCS12MacCalculatorBuilder macCalcBuilder, char[] password) throws PKCSException

Build the Pfx structure, protecting it with a MAC calculated against the passed in password.

Parameters
macCalcBuilder:PKCS12MacCalculatorBuilder

a builder for a PKCS12 mac calculator.

password:char[]

the password to use.

Returns:PKCS12PfxPdu

a Pfx object.

Exceptions
PKCSException:
on a encoding or processing error.