public class OpenPGPMessageGenerator extends AbstractOpenPGPDocumentSignatureGenerator<OpenPGPMessageGenerator>
LiteralDataPacket.
If however, the user provides one or more recipient certificates/keys
(addEncryptionCertificate(OpenPGPCertificate) /
addEncryptionCertificate(OpenPGPCertificate.OpenPGPComponentKey))
or message passphrases addEncryptionPassphrase(char[]), the message will be encrypted.
The encryption mechanism is automatically decided, based on the provided recipient certificates, aiming to maximize
interoperability.
If the user provides one or more signing keys by calling AbstractOpenPGPDocumentSignatureGenerator.addSigningKey(OpenPGPKey) or
AbstractOpenPGPDocumentSignatureGenerator.addSigningKey(OpenPGPKey.OpenPGPSecretKey, KeyPassphraseProvider, SignatureParameters.Callback),
the message will be signed.| Modifier and Type | Class and Description |
|---|---|
static interface |
OpenPGPMessageGenerator.ArmoredOutputStreamFactory |
static interface |
OpenPGPMessageGenerator.CompressionNegotiator |
| Modifier and Type | Field and Description |
|---|---|
static int |
BUFFER_SIZE |
boolean |
isAllowPadding |
defaultKeyPassphraseProvider, implementation, policy, signatureCallbacks, signatureGenerators, signingKeyPassphraseProviders, signingKeys, signingKeySelector| Constructor and Description |
|---|
OpenPGPMessageGenerator() |
OpenPGPMessageGenerator(OpenPGPImplementation implementation) |
OpenPGPMessageGenerator(OpenPGPImplementation implementation,
OpenPGPPolicy policy) |
| Modifier and Type | Method and Description |
|---|---|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate.OpenPGPComponentKey encryptionKey)
Add a (sub-)key to the set of recipient encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate.OpenPGPComponentKey encryptionKey,
boolean anonymousRecipient)
Add a (sub-)key to the set of recipient encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate recipientCertificate)
Add a recipients certificate to the set of encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate recipientCertificate,
boolean anonymousRecipient)
Add a recipients certificate to the set of encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate recipientCertificate,
SubkeySelector subkeySelector)
Add a recipients certificate to the set of encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionCertificate(OpenPGPCertificate recipientCertificate,
SubkeySelector subkeySelector,
boolean anonymousRecipient)
Add a recipients certificate to the set of encryption keys.
|
OpenPGPMessageGenerator |
addEncryptionPassphrase(char[] passphrase)
Add a message passphrase.
|
OpenPGPMessageOutputStream |
open(java.io.OutputStream out)
Open an
OpenPGPMessageOutputStream over the given output stream. |
OpenPGPMessageGenerator |
setAllowPadding(boolean allowPadding) |
OpenPGPMessageGenerator |
setArmored(boolean armored)
Specify, whether the output OpenPGP message will be ASCII armored or not.
|
OpenPGPMessageGenerator |
setArmorStreamFactory(OpenPGPMessageGenerator.ArmoredOutputStreamFactory factory)
Replace the
OpenPGPMessageGenerator.ArmoredOutputStreamFactory with a custom implementation. |
OpenPGPMessageGenerator |
setCompressionNegotiator(OpenPGPMessageGenerator.CompressionNegotiator compressionNegotiator)
Replace the default
OpenPGPMessageGenerator.CompressionNegotiator with a custom implementation. |
OpenPGPMessageGenerator |
setEncryptionKeySelector(SubkeySelector encryptionKeySelector)
Replace the default encryption key selector with a custom implementation.
|
OpenPGPMessageGenerator |
setFileMetadata(java.io.File file)
Set metadata (filename, modification date, binary format) from a file.
|
OpenPGPMessageGenerator |
setPasswordBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pbeNegotiator)
Replace the default
OpenPGPEncryptionNegotiator that gets to decide, which
MessageEncryptionMechanism mode to use if only password-based encryption is used. |
OpenPGPMessageGenerator |
setPublicKeyBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pkbeNegotiator)
Replace the default
OpenPGPEncryptionNegotiator that decides, which
MessageEncryptionMechanism mode to use if public-key encryption is used. |
OpenPGPMessageGenerator |
setSessionKeyExtractionCallback(PGPEncryptedDataGenerator.SessionKeyExtractionCallback callback)
Set a callback which fires once the session key for message encryption is known.
|
addKeyPassphrase, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSignToGenerator, initSignatureGenerator, setMissingKeyPassphraseCallback, setSigningKeySelectorpublic static final int BUFFER_SIZE
public boolean isAllowPadding
public OpenPGPMessageGenerator()
public OpenPGPMessageGenerator(OpenPGPImplementation implementation)
public OpenPGPMessageGenerator(OpenPGPImplementation implementation, OpenPGPPolicy policy)
public OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate recipientCertificate) throws InvalidEncryptionKeyException
SubkeySelector, which can be replaced by calling
setEncryptionKeySelector(SubkeySelector).
The recipient will be able to decrypt the message using their corresponding secret key.recipientCertificate - recipient certificate (public key)InvalidEncryptionKeyExceptionpublic OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate recipientCertificate, boolean anonymousRecipient) throws InvalidEncryptionKeyException
SubkeySelector, which can be replaced by calling
setEncryptionKeySelector(SubkeySelector).
The recipient will be able to decrypt the message using their corresponding secret key.
If anonymousRecipient is true, the recipients key-identifier will be obfuscated via a wildcard key-identifier.recipientCertificate - recipient certificate (public key)anonymousRecipient - whether to obfuscate the recipients identity within the messageInvalidEncryptionKeyExceptionpublic OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate recipientCertificate, SubkeySelector subkeySelector) throws InvalidEncryptionKeyException
SubkeySelector.
The recipient will be able to decrypt the message using their corresponding secret key.recipientCertificate - recipient certificate (public key)subkeySelector - selector for encryption subkeysInvalidEncryptionKeyException - if the certificate is not capable of encryptionpublic OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate recipientCertificate, SubkeySelector subkeySelector, boolean anonymousRecipient) throws InvalidEncryptionKeyException
SubkeySelector.
The recipient will be able to decrypt the message using their corresponding secret key.
If anonymous recipient is true, the identity of the recipient will be obfuscated via a wildcard key-identifier.recipientCertificate - recipient certificate (public key)subkeySelector - selector for encryption subkeysanonymousRecipient - whether to obfuscate the recipients identity within the messageInvalidEncryptionKeyException - if the certificate is not capable of encryptionpublic OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate.OpenPGPComponentKey encryptionKey) throws InvalidEncryptionKeyException
encryptionKey - encryption capable subkeyInvalidEncryptionKeyException - if the key is not capable of encryptionpublic OpenPGPMessageGenerator addEncryptionCertificate(OpenPGPCertificate.OpenPGPComponentKey encryptionKey, boolean anonymousRecipient) throws InvalidEncryptionKeyException
encryptionKey - encryption capable subkeyanonymousRecipient - whether to obfuscate the recipients identity within the messageInvalidEncryptionKeyException - if the key is not capable of encryptionpublic OpenPGPMessageGenerator addEncryptionPassphrase(char[] passphrase)
passphrase - passphrasepublic OpenPGPMessageGenerator setArmored(boolean armored)
armored - booleanpublic OpenPGPMessageGenerator setAllowPadding(boolean allowPadding)
public OpenPGPMessageGenerator setFileMetadata(java.io.File file)
file - filepublic OpenPGPMessageGenerator setSessionKeyExtractionCallback(PGPEncryptedDataGenerator.SessionKeyExtractionCallback callback)
callback - callbackpublic OpenPGPMessageOutputStream open(java.io.OutputStream out) throws PGPException, java.io.IOException
OpenPGPMessageOutputStream over the given output stream.out - output streamPGPException - if the output stream cannot be createdjava.io.IOExceptionpublic OpenPGPMessageGenerator setPasswordBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pbeNegotiator)
OpenPGPEncryptionNegotiator that gets to decide, which
MessageEncryptionMechanism mode to use if only password-based encryption is used.pbeNegotiator - custom PBE negotiator.public OpenPGPMessageGenerator setPublicKeyBasedEncryptionNegotiator(OpenPGPEncryptionNegotiator pkbeNegotiator)
OpenPGPEncryptionNegotiator that decides, which
MessageEncryptionMechanism mode to use if public-key encryption is used.pkbeNegotiator - custom encryption negotiator that gets to decide if PK-based encryption is usedpublic OpenPGPMessageGenerator setEncryptionKeySelector(SubkeySelector encryptionKeySelector)
encryptionKeySelector - selector for encryption (sub-)keyspublic OpenPGPMessageGenerator setCompressionNegotiator(OpenPGPMessageGenerator.CompressionNegotiator compressionNegotiator)
OpenPGPMessageGenerator.CompressionNegotiator with a custom implementation.
The OpenPGPMessageGenerator.CompressionNegotiator is used to negotiate, whether and how to compress the literal data packet.compressionNegotiator - negotiatorpublic OpenPGPMessageGenerator setArmorStreamFactory(OpenPGPMessageGenerator.ArmoredOutputStreamFactory factory)
OpenPGPMessageGenerator.ArmoredOutputStreamFactory with a custom implementation.factory - factory for ArmoredOutputStream instances