Top Fields Constructors Methods
org.bouncycastle.pkcs.jcajce

public Class JcePKCSPBEOutputEncryptorBuilder

extends Object
Class Inheritance
Imports
java.io.OutputStream, java.security.AlgorithmParameters, .Provider, .SecureRandom, javax.crypto.Cipher, .SecretKey, .SecretKeyFactory, javax.crypto.spec.PBEKeySpec, .SecretKeySpec, org.bouncycastle.asn1.ASN1ObjectIdentifier, .ASN1Primitive, org.bouncycastle.asn1.bc.BCObjectIdentifiers, org.bouncycastle.asn1.misc.MiscObjectIdentifiers, .ScryptParams, org.bouncycastle.asn1.pkcs.EncryptionScheme, .KeyDerivationFunc, .PBES2Parameters, .PBKDF2Params, .PKCS12PBEParams, .PKCSObjectIdentifiers, org.bouncycastle.asn1.x509.AlgorithmIdentifier, org.bouncycastle.crypto.util.PBKDF2Config, .PBKDFConfig, .ScryptConfig, org.bouncycastle.jcajce.PKCS12KeyWithParameters, org.bouncycastle.jcajce.io.CipherOutputStream, org.bouncycastle.jcajce.spec.ScryptKeySpec, org.bouncycastle.jcajce.util.DefaultJcaJceHelper, .JcaJceHelper, .NamedJcaJceHelper, .ProviderJcaJceHelper, org.bouncycastle.operator.AlgorithmNameFinder, .DefaultAlgorithmNameFinder, .DefaultSecretKeySizeProvider, .GenericKey, .OperatorCreationException, .OutputEncryptor, .SecretKeySizeProvider

Field Summary

Modifier and TypeField and Description
private ASN1ObjectIdentifier
private AlgorithmNameFinder
private JcaJceHelper
private int
private ASN1ObjectIdentifier
private SecretKeySizeProvider
private final PBKDFConfig
private PBKDF2Config.Builder
private SecureRandom

Constructor Summary

AccessConstructor and Description
public
public
JcePKCSPBEOutputEncryptorBuilder(PBKDFConfig
key derivation algorithm definition to use.
pbkdfAlgorithm
,
ASN1ObjectIdentifier
encryption algorithm to apply the derived key with.
keyEncryptionAlg
)

Constructor allowing different derivation functions such as PBKDF2 and scrypt.

Method Summary

Modifier and TypeMethod and Description
public OutputEncryptor
build(final char[] password)

private boolean
private static byte[]

Returns:

a byte array representing the password.
PKCS12PasswordToBytes
(char[]
a character array representing the password.
password
)

converts a password to a byte array according to the scheme in PKCS12 (unicode, big endian, 2 zero pad bytes at the end).

private static byte[]

Returns:

a byte array representing the password.
PKCS5PasswordToBytes
(char[]
a character array representing the password.
password
)

converts a password to a byte array according to the scheme in PKCS5 (ascii, no padding)

public JcePKCSPBEOutputEncryptorBuilder

Returns:

the current builder.
setIterationCount
(int
the iteration count to apply to the key creation.
iterationCount
)

Set the iteration count for the PBE calculation.

public JcePKCSPBEOutputEncryptorBuilder

Returns:

the current builder.
setKeySizeProvider
(SecretKeySizeProvider
a provider of integer secret key sizes.
keySizeProvider
)

Set the lookup provider of AlgorithmIdentifier returning key_size_in_bits used to handle PKCS5 decryption.

public JcePKCSPBEOutputEncryptorBuilder

Returns:

the current builder.
setPRF
(AlgorithmIdentifier
algorithm id for PRF.
prf
)

Set the PRF to use for key generation.

public JcePKCSPBEOutputEncryptorBuilder
public JcePKCSPBEOutputEncryptorBuilder
setProvider(String providerName)

public JcePKCSPBEOutputEncryptorBuilder
private SecretKey
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

algorithmback to summary
private ASN1ObjectIdentifier algorithm
algorithmNameFinderback to summary
private AlgorithmNameFinder algorithmNameFinder
helperback to summary
private JcaJceHelper helper
iterationCountback to summary
private int iterationCount
keyEncAlgorithmback to summary
private ASN1ObjectIdentifier keyEncAlgorithm
keySizeProviderback to summary
private SecretKeySizeProvider keySizeProvider
pbkdfback to summary
private final PBKDFConfig pbkdf
pbkdfBuilderback to summary
private PBKDF2Config.Builder pbkdfBuilder
randomback to summary
private SecureRandom random

Constructor Detail

JcePKCSPBEOutputEncryptorBuilderback to summary
public JcePKCSPBEOutputEncryptorBuilder(ASN1ObjectIdentifier keyEncryptionAlg)
JcePKCSPBEOutputEncryptorBuilderback to summary
public JcePKCSPBEOutputEncryptorBuilder(PBKDFConfig pbkdfAlgorithm, ASN1ObjectIdentifier keyEncryptionAlg)

Constructor allowing different derivation functions such as PBKDF2 and scrypt.

Parameters
pbkdfAlgorithm:PBKDFConfig

key derivation algorithm definition to use.

keyEncryptionAlg:ASN1ObjectIdentifier

encryption algorithm to apply the derived key with.

Method Detail

buildback to summary
public OutputEncryptor build(final char[] password) throws OperatorCreationException
isPKCS12back to summary
private boolean isPKCS12(ASN1ObjectIdentifier algorithm)
PKCS12PasswordToBytesback to summary
private static byte[] PKCS12PasswordToBytes(char[] password)

converts a password to a byte array according to the scheme in PKCS12 (unicode, big endian, 2 zero pad bytes at the end).

Parameters
password:char[]

a character array representing the password.

Returns:byte[]

a byte array representing the password.

PKCS5PasswordToBytesback to summary
private static byte[] PKCS5PasswordToBytes(char[] password)

converts a password to a byte array according to the scheme in PKCS5 (ascii, no padding)

Parameters
password:char[]

a character array representing the password.

Returns:byte[]

a byte array representing the password.

setIterationCountback to summary
public JcePKCSPBEOutputEncryptorBuilder setIterationCount(int iterationCount)

Set the iteration count for the PBE calculation.

Parameters
iterationCount:int

the iteration count to apply to the key creation.

Returns:JcePKCSPBEOutputEncryptorBuilder

the current builder.

Exceptions
IllegalStateException:
if this builder was intialised with a PBKDFDef
setKeySizeProviderback to summary
public JcePKCSPBEOutputEncryptorBuilder setKeySizeProvider(SecretKeySizeProvider keySizeProvider)

Set the lookup provider of AlgorithmIdentifier returning key_size_in_bits used to handle PKCS5 decryption.

Parameters
keySizeProvider:SecretKeySizeProvider

a provider of integer secret key sizes.

Returns:JcePKCSPBEOutputEncryptorBuilder

the current builder.

setPRFback to summary
public JcePKCSPBEOutputEncryptorBuilder setPRF(AlgorithmIdentifier prf)

Set the PRF to use for key generation. By default this is HmacSHA1.

Parameters
prf:AlgorithmIdentifier

algorithm id for PRF.

Returns:JcePKCSPBEOutputEncryptorBuilder

the current builder.

Exceptions
IllegalStateException:
if this builder was intialised with a PBKDFDef
setProviderback to summary
public JcePKCSPBEOutputEncryptorBuilder setProvider(Provider provider)
setProviderback to summary
public JcePKCSPBEOutputEncryptorBuilder setProvider(String providerName)
setRandomback to summary
public JcePKCSPBEOutputEncryptorBuilder setRandom(SecureRandom random)
simplifyPbeKeyback to summary
private SecretKey simplifyPbeKey(SecretKey key)