org.bouncycastle.openpgp

Class PGPEncryptedDataGenerator

public class PGPEncryptedDataGenerator extends Object implements SymmetricKeyAlgorithmTags, StreamGenerator

Generator for encrypted objects.
Constructor Summary
PGPEncryptedDataGenerator(int encAlgorithm, SecureRandom rand, String provider)
Base constructor.
PGPEncryptedDataGenerator(int encAlgorithm, boolean withIntegrityPacket, SecureRandom rand, String provider)
Creates a cipher stream which will have an integrity packet associated with it.
PGPEncryptedDataGenerator(int encAlgorithm, SecureRandom rand, boolean oldFormat, String provider)
Base constructor.
Method Summary
voidaddMethod(char[] passPhrase)
Add a PBE encryption method to the encrypted object.
voidaddMethod(PGPPublicKey key)
Add a public key encrypted session key to the encrypted object.
voidclose()
Close off the encrypted object - this is equivalent to calling close on the stream returned by the open() method.
OutputStreamopen(OutputStream out, long length)
Return an outputstream which will encrypt the data as it is written to it.
OutputStreamopen(OutputStream out, byte[] buffer)
Return an outputstream which will encrypt the data as it is written to it.

Constructor Detail

PGPEncryptedDataGenerator

public PGPEncryptedDataGenerator(int encAlgorithm, SecureRandom rand, String provider)
Base constructor.

Parameters: encAlgorithm the symmetric algorithm to use. rand source of randomness provider the provider to use for encryption algorithms.

PGPEncryptedDataGenerator

public PGPEncryptedDataGenerator(int encAlgorithm, boolean withIntegrityPacket, SecureRandom rand, String provider)
Creates a cipher stream which will have an integrity packet associated with it.

Parameters: encAlgorithm withIntegrityPacket rand provider

PGPEncryptedDataGenerator

public PGPEncryptedDataGenerator(int encAlgorithm, SecureRandom rand, boolean oldFormat, String provider)
Base constructor.

Parameters: encAlgorithm the symmetric algorithm to use. rand source of randomness oldFormat PGP 2.6.x compatability required. provider the provider to use for encryption algorithms.

Method Detail

addMethod

public void addMethod(char[] passPhrase)
Add a PBE encryption method to the encrypted object.

Parameters: passPhrase

Throws: NoSuchProviderException PGPException

addMethod

public void addMethod(PGPPublicKey key)
Add a public key encrypted session key to the encrypted object.

Parameters: key

Throws: NoSuchProviderException PGPException

close

public void close()
Close off the encrypted object - this is equivalent to calling close on the stream returned by the open() method.

Throws: IOException

open

public OutputStream open(OutputStream out, long length)
Return an outputstream which will encrypt the data as it is written to it. The stream can be closed off by either calling close() on the stream or close() on the generator.

Parameters: out length

Returns: OutputStream

Throws: IOException PGPException

open

public OutputStream open(OutputStream out, byte[] buffer)
Return an outputstream which will encrypt the data as it is written to it. The stream will be written out in chunks according to the size of the passed in buffer. The stream can be closed off by either calling close() on the stream or close() on the generator.

Note: if the buffer is not a power of 2 in length only the largest power of 2 bytes worth of the buffer will be used.

Parameters: out buffer the buffer to use.

Returns: OutputStream

Throws: IOException PGPException