Top Description Inners Fields Constructors Methods
org.bouncycastle.openpgp.operator.jcajce

public Class JcePGPDataEncryptorBuilder

extends Object
implements PGPDataEncryptorBuilder
Class Inheritance
All Implemented Interfaces
org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder
Imports
java.io.OutputStream, java.security.InvalidAlgorithmParameterException, .InvalidKeyException, .Provider, .SecureRandom, javax.crypto.Cipher, javax.crypto.spec.IvParameterSpec, org.bouncycastle.bcpg.AEADEncDataPacket, .SymmetricKeyAlgorithmTags, org.bouncycastle.jcajce.io.CipherOutputStream, org.bouncycastle.jcajce.util.DefaultJcaJceHelper, .NamedJcaJceHelper, .ProviderJcaJceHelper, org.bouncycastle.openpgp.PGPException, org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor, .PGPDataEncryptor, .PGPDataEncryptorBuilder, .PGPDigestCalculator, org.bouncycastle.util.Arrays

PGPDataEncryptorBuilder implementation that sources cryptographic primitives using the JCE APIs.

By default, cryptographic primitives will be loaded using the default JCE load order (i.e. without specifying a provider). A specific provider can be specified using one of the setProvider(String) methods.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
private class

Field Summary

Modifier and TypeField and Description
private int
private int
private int
private OperatorHelper
private SecureRandom
private boolean

Constructor Summary

AccessConstructor and Description
public
JcePGPDataEncryptorBuilder(int encAlgorithm)

Constructs a new data encryptor builder for a specified cipher type.

Method Summary

Modifier and TypeMethod and Description
public PGPDataEncryptor
build(byte[]
the bytes of the key to use for the cipher.
keyBytes
)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.build.

Builds a data encryptor using the algorithm configured for this builder.
public int
getAlgorithm()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getAlgorithm.

The encryption algorithm used by data encryptors created by this builder.
public SecureRandom
getSecureRandom()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getSecureRandom.

Gets the SecureRandom instance used by this builder.
public JcePGPDataEncryptorBuilder

Returns:

the current builder.
setProvider
(Provider
the JCE provider to use.
provider
)

Sets the JCE provider to source cryptographic primitives from.

public JcePGPDataEncryptorBuilder

Returns:

the current builder.
setProvider
(String
the name of the JCE provider to use.
providerName
)

Sets the JCE provider to source cryptographic primitives from.

public JcePGPDataEncryptorBuilder

Returns:

the current builder.
setSecureRandom
(SecureRandom
the secure random to be used.
random
)

Provide a user defined source of randomness.

public JcePGPDataEncryptorBuilder
setWithAEAD(int
the AEAD mode to use.
aeadAlgorithm
,
int
the size of the chunks to be processed with each nonce.
chunkSize
)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setWithAEAD.

Sets whether or not the resulting encrypted data will be protected using an AEAD mode.
public JcePGPDataEncryptorBuilder

Returns:

the current builder.
setWithIntegrityPacket
(boolean
true if an integrity packet is to be included, false otherwise.
withIntegrityPacket
)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setWithIntegrityPacket.

Sets whether or not the resulting encrypted data will be protected using an integrity packet.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aeadAlgorithmback to summary
private int aeadAlgorithm
chunkSizeback to summary
private int chunkSize
encAlgorithmback to summary
private int encAlgorithm
helperback to summary
private OperatorHelper helper
randomback to summary
private SecureRandom random
withIntegrityPacketback to summary
private boolean withIntegrityPacket

Constructor Detail

JcePGPDataEncryptorBuilderback to summary
public JcePGPDataEncryptorBuilder(int encAlgorithm)

Constructs a new data encryptor builder for a specified cipher type.

Parameters
encAlgorithm:int

one of the supported symmetric cipher algorithms. May not be SymmetricKeyAlgorithmTags#NULL.

Method Detail

buildback to summary
public PGPDataEncryptor build(byte[] keyBytes) throws PGPException

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.build.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.build.

Builds a data encryptor using the algorithm configured for this builder.

Parameters
keyBytes:byte[]

the bytes of the key to use for the cipher.

Returns:PGPDataEncryptor

a data encryptor with an initialised cipher.

Exceptions
PGPException:
if an error occurs initialising the configured encryption.
getAlgorithmback to summary
public int getAlgorithm()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getAlgorithm.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getAlgorithm.

The encryption algorithm used by data encryptors created by this builder.

Returns:int

one of the symmetric encryption algorithms.

getSecureRandomback to summary
public SecureRandom getSecureRandom()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getSecureRandom.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getSecureRandom.

Gets the SecureRandom instance used by this builder.

If a SecureRandom has not been explicitly configured, a default SecureRandom is constructed and retained by the this builder.

setProviderback to summary
public JcePGPDataEncryptorBuilder setProvider(Provider provider)

Sets the JCE provider to source cryptographic primitives from.

Parameters
provider:Provider

the JCE provider to use.

Returns:JcePGPDataEncryptorBuilder

the current builder.

setProviderback to summary
public JcePGPDataEncryptorBuilder setProvider(String providerName)

Sets the JCE provider to source cryptographic primitives from.

Parameters
providerName:String

the name of the JCE provider to use.

Returns:JcePGPDataEncryptorBuilder

the current builder.

setSecureRandomback to summary
public JcePGPDataEncryptorBuilder setSecureRandom(SecureRandom random)

Provide a user defined source of randomness.

If no SecureRandom is configured, a default SecureRandom will be used.

Parameters
random:SecureRandom

the secure random to be used.

Returns:JcePGPDataEncryptorBuilder

the current builder.

setWithAEADback to summary
public JcePGPDataEncryptorBuilder setWithAEAD(int aeadAlgorithm, int chunkSize)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setWithAEAD.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setWithAEAD.

Sets whether or not the resulting encrypted data will be protected using an AEAD mode. The chunkSize is used as a power of two, result in blocks (1 << chunkSize) containing data with an extra 16 bytes for the tag. The minimum chunkSize is 6.

Parameters
aeadAlgorithm:int

the AEAD mode to use.

chunkSize:int

the size of the chunks to be processed with each nonce.

setWithIntegrityPacketback to summary
public JcePGPDataEncryptorBuilder setWithIntegrityPacket(boolean withIntegrityPacket)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setWithIntegrityPacket.

Sets whether or not the resulting encrypted data will be protected using an integrity packet.

Parameters
withIntegrityPacket:boolean

true if an integrity packet is to be included, false otherwise.

Returns:JcePGPDataEncryptorBuilder

the current builder.

org.bouncycastle.openpgp.operator.jcajce back to summary

private Class JcePGPDataEncryptorBuilder.MyAeadDataEncryptor

extends Object
implements PGPAEADDataEncryptor
Class Inheritance
  • java.lang.Object
  • org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder.MyAeadDataEncryptor
All Implemented Interfaces
org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor, org.bouncycastle.openpgp.operator.PGPDataEncryptor

Field Summary

Modifier and TypeField and Description
private final Cipher
c

private final byte[]
private final byte[]

Constructor Summary

AccessConstructor and Description
pack-priv
MyAeadDataEncryptor(byte[] keyBytes)

Method Summary

Modifier and TypeMethod and Description
public int
public int
getBlockSize()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Gets the block size of the underlying cipher used by this encryptor.
public int
public PGPDigestCalculator
getIntegrityCalculator()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Obtains the integrity check calculator configured for this encryptor instance.
public byte[]
public OutputStream
getOutputStream(OutputStream
the stream to wrap and write encrypted data to.
out
)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Constructs an encrypting output stream that encrypts data using the underlying cipher of this encryptor.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cback to summary
private final Cipher c
ivback to summary
private final byte[] iv
keyBytesback to summary
private final byte[] keyBytes

Constructor Detail

MyAeadDataEncryptorback to summary
pack-priv MyAeadDataEncryptor(byte[] keyBytes) throws PGPException

Method Detail

getAEADAlgorithmback to summary
public int getAEADAlgorithm()

Implements org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor.getAEADAlgorithm.

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Gets the block size of the underlying cipher used by this encryptor.

Returns:int

the block size in bytes.

getChunkSizeback to summary
public int getChunkSize()

Implements org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor.getChunkSize.

getIntegrityCalculatorback to summary
public PGPDigestCalculator getIntegrityCalculator()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Obtains the integrity check calculator configured for this encryptor instance.

Returns:PGPDigestCalculator

the integrity check calculator, or null if no integrity checking was configured.

getIVback to summary
public byte[] getIV()

Implements org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor.getIV.

getOutputStreamback to summary
public OutputStream getOutputStream(OutputStream out)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Constructs an encrypting output stream that encrypts data using the underlying cipher of this encryptor.

The cipher instance in this encryptor is used for all output streams obtained from this method, so it should only be invoked once.

Parameters
out:OutputStream

the stream to wrap and write encrypted data to.

Returns:OutputStream

a cipher output stream appropriate to the type of this data encryptor.

org.bouncycastle.openpgp.operator.jcajce back to summary

private Class JcePGPDataEncryptorBuilder.MyPGPDataEncryptor

extends Object
implements PGPDataEncryptor
Class Inheritance
  • java.lang.Object
  • org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder.MyPGPDataEncryptor
All Implemented Interfaces
org.bouncycastle.openpgp.operator.PGPDataEncryptor

Field Summary

Modifier and TypeField and Description
private final Cipher
c

Constructor Summary

AccessConstructor and Description
pack-priv
MyPGPDataEncryptor(byte[] keyBytes)

Method Summary

Modifier and TypeMethod and Description
public int
getBlockSize()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Gets the block size of the underlying cipher used by this encryptor.
public PGPDigestCalculator
getIntegrityCalculator()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Obtains the integrity check calculator configured for this encryptor instance.
public OutputStream
getOutputStream(OutputStream
the stream to wrap and write encrypted data to.
out
)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Constructs an encrypting output stream that encrypts data using the underlying cipher of this encryptor.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cback to summary
private final Cipher c

Constructor Detail

MyPGPDataEncryptorback to summary
pack-priv MyPGPDataEncryptor(byte[] keyBytes) throws PGPException

Method Detail

getBlockSizeback to summary
public int getBlockSize()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getBlockSize.

Gets the block size of the underlying cipher used by this encryptor.

Returns:int

the block size in bytes.

getIntegrityCalculatorback to summary
public PGPDigestCalculator getIntegrityCalculator()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getIntegrityCalculator.

Obtains the integrity check calculator configured for this encryptor instance.

Returns:PGPDigestCalculator

the integrity check calculator, or null if no integrity checking was configured.

getOutputStreamback to summary
public OutputStream getOutputStream(OutputStream out)

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Doc from org.bouncycastle.openpgp.operator.PGPDataEncryptor.getOutputStream.

Constructs an encrypting output stream that encrypts data using the underlying cipher of this encryptor.

The cipher instance in this encryptor is used for all output streams obtained from this method, so it should only be invoked once.

Parameters
out:OutputStream

the stream to wrap and write encrypted data to.

Returns:OutputStream

a cipher output stream appropriate to the type of this data encryptor.