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

public Class BcPGPDataEncryptorBuilder

extends Object
implements PGPDataEncryptorBuilder
Class Inheritance
All Implemented Interfaces
org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder
Imports
java.io.OutputStream, java.security.SecureRandom, org.bouncycastle.bcpg.AEADUtils, .SymmetricKeyAlgorithmTags, .SymmetricKeyUtils, org.bouncycastle.crypto.BlockCipher, .BufferedBlockCipher, org.bouncycastle.crypto.io.CipherOutputStream, org.bouncycastle.crypto.modes.AEADBlockCipher, org.bouncycastle.crypto.params.KeyParameter, org.bouncycastle.openpgp.PGPException, org.bouncycastle.openpgp.operator.PGPAEADDataEncryptor, .PGPDataEncryptor, .PGPDataEncryptorBuilder, .PGPDigestCalculator, org.bouncycastle.util.Arrays

PGPDataEncryptorBuilder implementation that uses the Bouncy Castle lightweight API to implement cryptographic primitives.

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 boolean
private SecureRandom
private boolean

Constructor Summary

AccessConstructor and Description
public
BcPGPDataEncryptorBuilder(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
public int
getAlgorithm()

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

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

public int
public SecureRandom
getSecureRandom()

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

Gets the SecureRandom instance used by this builder.

public boolean
public BcPGPDataEncryptorBuilder

Returns:

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

Provide a user defined source of randomness.

public BcPGPDataEncryptorBuilder
public BcPGPDataEncryptorBuilder
public BcPGPDataEncryptorBuilder

Returns:

builder
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 the resulting encrypted data will be protected using an AEAD mode.

public BcPGPDataEncryptorBuilder

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 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
isV5StyleAEADback to summary
private boolean isV5StyleAEAD
randomback to summary
private SecureRandom random
withIntegrityPacketback to summary
private boolean withIntegrityPacket

Constructor Detail

BcPGPDataEncryptorBuilderback to summary
public BcPGPDataEncryptorBuilder(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.

Annotations
@Override
Exceptions
PGPException:
if an error occurs initialising the configured encryption.
getAeadAlgorithmback to summary
public int getAeadAlgorithm()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getAeadAlgorithm.

Annotations
@Override
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.

Annotations
@Override
getChunkSizeback to summary
public int getChunkSize()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.getChunkSize.

Annotations
@Override
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.

Annotations
@Override
isV5StyleAEADback to summary
public boolean isV5StyleAEAD()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.isV5StyleAEAD.

Annotations
@Override
setSecureRandomback to summary
public BcPGPDataEncryptorBuilder 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:BcPGPDataEncryptorBuilder

the current builder.

setUseV5AEADback to summary
public BcPGPDataEncryptorBuilder setUseV5AEAD()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setUseV5AEAD.

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

Specify we are using V5 AEAD.

Returns:BcPGPDataEncryptorBuilder

the current builder

setUseV6AEADback to summary
public BcPGPDataEncryptorBuilder setUseV6AEAD()

Implements org.bouncycastle.openpgp.operator.PGPDataEncryptorBuilder.setUseV6AEAD.

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

Specify we are using V6 AEAD.

Returns:BcPGPDataEncryptorBuilder

the current builder

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

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

Sets whether 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.

Returns:BcPGPDataEncryptorBuilder

builder

Annotations
@Override
setWithIntegrityPacketback to summary
public BcPGPDataEncryptorBuilder setWithIntegrityPacket(boolean withIntegrityPacket)

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

Sets whether 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:BcPGPDataEncryptorBuilder

the current builder.

Annotations
@Override
org.bouncycastle.openpgp.operator.bc back to summary

private Class BcPGPDataEncryptorBuilder.MyAeadDataEncryptor

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

Field Summary

Modifier and TypeField and Description
private final AEADBlockCipher
c

private final boolean
private final byte[]
private final byte[]

Constructor Summary

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

Create a new data decryptor using AEAD.

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 AEADBlockCipher c
isV5StyleAEADback to summary
private final boolean isV5StyleAEAD
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

Create a new data decryptor using AEAD. If the OpenPGP v5 style AEAD is used, keyBytes contains the key. The IV is randomly generated. If however OpenPGP v6 style AEAD is used, keyBytes contains M+N-8 bytes. The first M bytes contain the key, the remaining N-8 bytes contain the IV.

Parameters
keyBytes:byte[]

key or key and iv

Method Detail

getAEADAlgorithmback to summary
public int getAEADAlgorithm()

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

Annotations
@Override
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.

Annotations
@Override
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.

Annotations
@Override
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.bc back to summary

private Class BcPGPDataEncryptorBuilder.MyPGPDataEncryptor

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

Field Summary

Modifier and TypeField and Description
private final BufferedBlockCipher
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 BufferedBlockCipher 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.