Class EncryptionOptions
- java.lang.Object
- 
- org.pgpainless.encryption_signing.EncryptionOptions
 
- 
 public class EncryptionOptions extends Object Options for the encryption process. This class can be used to set encryption parameters, like encryption keys and passphrases, algorithms etc. A typical use might look like follows:
 To use a custom symmetric encryption algorithm, useEncryptionOptions opt = new EncryptionOptions(); opt.addRecipient(aliceKey, "Alice <alice@wonderland.lit>"); opt.addPassphrase(Passphrase.fromPassword("AdditionalDecryptionPassphrase123"));overrideEncryptionAlgorithm(SymmetricKeyAlgorithm). This will cause PGPainless to use the provided algorithm for message encryption, instead of negotiating an algorithm by inspecting the provided recipient keys. By default, PGPainless will only encrypt to a single encryption capable subkey per recipient key. This behavior can be changed, e.g. by calling
 when adding the recipient key.opt.addRecipient(aliceKey, EncryptionOptions.encryptToAllCapableSubkeys());
- 
- 
Nested Class SummaryNested Classes Modifier and Type Class Description static interfaceEncryptionOptions.EncryptionKeySelector
 - 
Constructor SummaryConstructors Constructor Description EncryptionOptions()Encrypt to keys both carrying the key flagKeyFlag.ENCRYPT_COMMSorKeyFlag.ENCRYPT_STORAGE.EncryptionOptions(EncryptionPurpose purpose)
 - 
Method SummaryAll Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description EncryptionOptionsaddEncryptionMethod(org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator encryptionMethod)Add anPGPKeyEncryptionMethodGeneratorwhich will be used to encrypt the message.EncryptionOptionsaddPassphrase(Passphrase passphrase)Add a symmetric passphrase which the message will be encrypted to.EncryptionOptionsaddRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key)Add a recipient by providing a key.EncryptionOptionsaddRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, String userId)Add a recipient by providing a key and recipient user-id.EncryptionOptionsaddRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, String userId, EncryptionOptions.EncryptionKeySelector encryptionKeySelectionStrategy)Add a recipient by providing a key and recipient user-id, as well as a strategy for selecting one or multiple encryption capable subkeys from the key.EncryptionOptionsaddRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, EncryptionOptions.EncryptionKeySelector encryptionKeySelectionStrategy)Add a recipient by providing a key and an encryption key selection strategy.EncryptionOptionsaddRecipients(Iterable<org.bouncycastle.openpgp.PGPPublicKeyRing> keys)Add all key rings in the providedIterable(e.g.EncryptionOptionsaddRecipients(Iterable<org.bouncycastle.openpgp.PGPPublicKeyRing> keys, EncryptionOptions.EncryptionKeySelector selector)Add all key rings in the providedIterable(e.g.static EncryptionOptionsencryptCommunications()Factory method to create anEncryptionOptionsobject which will encrypt for keys which carry the flagKeyFlag.ENCRYPT_COMMS.static EncryptionOptionsencryptDataAtRest()Factory method to create anEncryptionOptionsobject which will encrypt for keys which carry the flagKeyFlag.ENCRYPT_STORAGE.static EncryptionOptions.EncryptionKeySelectorencryptToAllCapableSubkeys()Encrypt to any valid, encryption capable subkey on the key ring.static EncryptionOptions.EncryptionKeySelectorencryptToFirstSubkey()Only encrypt to the first valid encryption capable subkey we stumble upon.EncryptionOptionsoverrideEncryptionAlgorithm(SymmetricKeyAlgorithm encryptionAlgorithm)Override the used symmetric encryption algorithm.
 
- 
- 
- 
Constructor Detail- 
EncryptionOptionspublic EncryptionOptions() Encrypt to keys both carrying the key flagKeyFlag.ENCRYPT_COMMSorKeyFlag.ENCRYPT_STORAGE.
 - 
EncryptionOptionspublic EncryptionOptions(EncryptionPurpose purpose) 
 
- 
 - 
Method Detail- 
encryptCommunicationspublic static EncryptionOptions encryptCommunications() Factory method to create anEncryptionOptionsobject which will encrypt for keys which carry the flagKeyFlag.ENCRYPT_COMMS.- Returns:
- encryption options
 
 - 
encryptDataAtRestpublic static EncryptionOptions encryptDataAtRest() Factory method to create anEncryptionOptionsobject which will encrypt for keys which carry the flagKeyFlag.ENCRYPT_STORAGE.- Returns:
- encryption options
 
 - 
addRecipientspublic EncryptionOptions addRecipients(Iterable<org.bouncycastle.openpgp.PGPPublicKeyRing> keys) Add all key rings in the providedIterable(e.g.PGPPublicKeyRingCollection) as recipients.- Parameters:
- keys- keys
- Returns:
- this
 
 - 
addRecipientspublic EncryptionOptions addRecipients(@Nonnull Iterable<org.bouncycastle.openpgp.PGPPublicKeyRing> keys, @Nonnull EncryptionOptions.EncryptionKeySelector selector) Add all key rings in the providedIterable(e.g.PGPPublicKeyRingCollection) as recipients. Per key ring, the selector is applied to select one or more encryption subkeys.- Parameters:
- keys- keys
- selector- encryption key selector
- Returns:
- this
 
 - 
addRecipientpublic EncryptionOptions addRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, String userId) Add a recipient by providing a key and recipient user-id. The user-id is used to determine the recipients preferences (algorithms etc.).- Parameters:
- key- key ring
- userId- user id
- Returns:
- this
 
 - 
addRecipientpublic EncryptionOptions addRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, String userId, EncryptionOptions.EncryptionKeySelector encryptionKeySelectionStrategy) Add a recipient by providing a key and recipient user-id, as well as a strategy for selecting one or multiple encryption capable subkeys from the key.- Parameters:
- key- key
- userId- user-id
- encryptionKeySelectionStrategy- strategy to select one or more encryption subkeys to encrypt to
- Returns:
- this
 
 - 
addRecipientpublic EncryptionOptions addRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key) Add a recipient by providing a key.- Parameters:
- key- key ring
- Returns:
- this
 
 - 
addRecipientpublic EncryptionOptions addRecipient(org.bouncycastle.openpgp.PGPPublicKeyRing key, EncryptionOptions.EncryptionKeySelector encryptionKeySelectionStrategy) Add a recipient by providing a key and an encryption key selection strategy.- Parameters:
- key- key ring
- encryptionKeySelectionStrategy- strategy used to select one or multiple encryption subkeys.
- Returns:
- this
 
 - 
addPassphrasepublic EncryptionOptions addPassphrase(Passphrase passphrase) Add a symmetric passphrase which the message will be encrypted to.- Parameters:
- passphrase- passphrase
- Returns:
- this
 
 - 
addEncryptionMethodpublic EncryptionOptions addEncryptionMethod(org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator encryptionMethod) Add anPGPKeyEncryptionMethodGeneratorwhich will be used to encrypt the message. Method generators are eitherPBEKeyEncryptionMethodGenerator(passphrase) orPGPKeyEncryptionMethodGenerator(public key). This method is intended for advanced users to allow encryption for specific subkeys. This can come in handy for example if data needs to be encrypted to a subkey that's ignored by PGPainless.- Parameters:
- encryptionMethod- encryption method
- Returns:
- this
 
 - 
overrideEncryptionAlgorithmpublic EncryptionOptions overrideEncryptionAlgorithm(SymmetricKeyAlgorithm encryptionAlgorithm) Override the used symmetric encryption algorithm. The symmetric encryption algorithm is used to encrypt the message itself, while the used symmetric key will be encrypted to all recipients using public key cryptography. If the algorithm is not overridden, a suitable algorithm will be negotiated.- Parameters:
- encryptionAlgorithm- encryption algorithm override
 
 - 
encryptToFirstSubkeypublic static EncryptionOptions.EncryptionKeySelector encryptToFirstSubkey() Only encrypt to the first valid encryption capable subkey we stumble upon.- Returns:
- encryption key selector
 
 - 
encryptToAllCapableSubkeyspublic static EncryptionOptions.EncryptionKeySelector encryptToAllCapableSubkeys() Encrypt to any valid, encryption capable subkey on the key ring.- Returns:
- encryption key selector
 
 
- 
 
-