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) |
addKeyPassphrase, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSigningKey, addSignToGenerator, initSignatureGenerator, setMissingKeyPassphraseCallback, setSigningKeySelector
public 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)InvalidEncryptionKeyException
public 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.OpenPGPComponentKey encryptionKey) throws InvalidEncryptionKeyException
encryptionKey
- encryption capable subkeyInvalidEncryptionKeyException
- 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.IOException
public 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