Package org.bouncycastle.openpgp.api
Class OpenPGPImplementation
java.lang.Object
org.bouncycastle.openpgp.api.OpenPGPImplementation
- Direct Known Subclasses:
BcOpenPGPImplementation
,JcaOpenPGPImplementation
Bouncy Castle provides two implementations of OpenPGP operators.
The
JCA/JCEimplementation makes use of Java Cryptography Architecture and the Java Cryptography Extension, while
Bcuses Bouncy Castles Lightweight Cryptography API. The purpose of
OpenPGPImplementation
is to define a shared interface for instantiating concrete
objects of either API.
It is advised to define the desired implementation by calling setInstance(OpenPGPImplementation)
and
acquiring it via getInstance()
, as swapping out the entire implementation can then be done by
replacing the instance in one single place.
This pattern was successfully explored by PGPainless.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic OpenPGPImplementation
Return the currently setOpenPGPImplementation
instance.abstract KeyFingerPrintCalculator
abstract PBEDataDecryptorFactory
pbeDataDecryptorFactory
(char[] messagePassphrase) Return an instance of thePBEDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages that were encrypted symmetrically with a passphrase.abstract PBEKeyEncryptionMethodGenerator
pbeKeyEncryptionMethodGenerator
(char[] messagePassphrase) Return an instance ofPBEKeyEncryptionMethodGenerator
which is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.SALTED_AND_ITERATED
mode.abstract PBEKeyEncryptionMethodGenerator
pbeKeyEncryptionMethodGenerator
(char[] messagePassphrase, S2K.Argon2Params argon2Params) Return an instance ofPBEKeyEncryptionMethodGenerator
which is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.ARGON_2
mode.abstract PBESecretKeyDecryptorBuilderProvider
Return an instance ofPBESecretKeyDecryptorBuilderProvider
which is responsible for providing implementations needed for secret key unlocking.abstract PBESecretKeyEncryptorFactory
pbeSecretKeyEncryptorFactory
(boolean aead) abstract PBESecretKeyEncryptorFactory
pbeSecretKeyEncryptorFactory
(boolean aead, int symmetricKeyAlgorithm, int iterationCount) abstract PGPContentSignerBuilder
pgpContentSignerBuilder
(int publicKeyAlgorithm, int hashAlgorithm) Return an instance ofPGPContentSignerBuilder
, which is responsible for providing concrete implementations needed for signature creation.abstract PGPContentSignerBuilderProvider
pgpContentSignerBuilderProvider
(int hashAlgorithmId) abstract PGPContentVerifierBuilderProvider
Return an instance ofPGPContentVerifierBuilderProvider
which is responsible for providing implementations needed for signature verification.abstract PGPDataEncryptorBuilder
pgpDataEncryptorBuilder
(int symmetricKeyAlgorithm) Return an instance ofPGPDataEncryptorBuilder
which is responsible for providing implementations needed for creating encrypted data packets.abstract PGPDigestCalculatorProvider
Return an instance of thePGPDigestCalculatorProvider
, which is responsible for providing concretePGPDigestCalculator
implementations.abstract PGPKeyPairGeneratorProvider
abstract PGPObjectFactory
pgpObjectFactory
(InputStream packetInputStream) Return an instance ofPGPObjectFactory
based on the givenInputStream
.policy()
abstract PublicKeyDataDecryptorFactory
publicKeyDataDecryptorFactory
(PGPPrivateKey decryptionKey) Return an instance of thePublicKeyDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages using aPGPPrivateKey
.publicKeyKeyEncryptionMethodGenerator
(PGPPublicKey encryptionSubkey) Return an instance ofPublicKeyKeyEncryptionMethodGenerator
which is responsible for creating public-key-based encryptors for OpenPGP messages.abstract SessionKeyDataDecryptorFactory
sessionKeyDataDecryptorFactory
(PGPSessionKey sessionKey) Return an instance of theSessionKeyDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages using aPGPSessionKey
.static void
setInstance
(OpenPGPImplementation implementation) Replace theOpenPGPImplementation
instance that is returned bygetInstance()
.setPolicy
(OpenPGPPolicy policy)
-
Constructor Details
-
OpenPGPImplementation
public OpenPGPImplementation()
-
-
Method Details
-
setInstance
Replace theOpenPGPImplementation
instance that is returned bygetInstance()
.- Parameters:
implementation
- instance
-
getInstance
Return the currently setOpenPGPImplementation
instance. The default isBcOpenPGPImplementation
.- Returns:
- instance
-
policy
-
setPolicy
-
pgpObjectFactory
Return an instance ofPGPObjectFactory
based on the givenInputStream
.- Parameters:
packetInputStream
- packet input stream- Returns:
- object factory
-
pgpContentVerifierBuilderProvider
Return an instance ofPGPContentVerifierBuilderProvider
which is responsible for providing implementations needed for signature verification.- Returns:
- content verifier builder provider
-
pbeSecretKeyDecryptorBuilderProvider
Return an instance ofPBESecretKeyDecryptorBuilderProvider
which is responsible for providing implementations needed for secret key unlocking.- Returns:
- secret key decryptor builder provider
-
pgpDataEncryptorBuilder
Return an instance ofPGPDataEncryptorBuilder
which is responsible for providing implementations needed for creating encrypted data packets.- Parameters:
symmetricKeyAlgorithm
- symmetric encryption algorithm- Returns:
- data encryptor builder
-
publicKeyKeyEncryptionMethodGenerator
public abstract PublicKeyKeyEncryptionMethodGenerator publicKeyKeyEncryptionMethodGenerator(PGPPublicKey encryptionSubkey) Return an instance ofPublicKeyKeyEncryptionMethodGenerator
which is responsible for creating public-key-based encryptors for OpenPGP messages. Public-key-based encryptors are used when a message is encrypted for a recipients public key.- Parameters:
encryptionSubkey
- subkey for which a message shall be encrypted- Returns:
- public-key key-encryption method generator
-
pbeKeyEncryptionMethodGenerator
public abstract PBEKeyEncryptionMethodGenerator pbeKeyEncryptionMethodGenerator(char[] messagePassphrase) Return an instance ofPBEKeyEncryptionMethodGenerator
which is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.SALTED_AND_ITERATED
mode. Symmetric-key-based encryptors are used when a message is encrypted using a passphrase.- Parameters:
messagePassphrase
- passphrase to encrypt the message with- Returns:
- pbe key encryption method generator
-
pbeKeyEncryptionMethodGenerator
public abstract PBEKeyEncryptionMethodGenerator pbeKeyEncryptionMethodGenerator(char[] messagePassphrase, S2K.Argon2Params argon2Params) Return an instance ofPBEKeyEncryptionMethodGenerator
which is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.ARGON_2
mode. Symmetric-key-based encryptors are used when a message is encrypted using a passphrase.- Parameters:
messagePassphrase
- passphrase to encrypt the message withargon2Params
- parameters for the Argon2 hash function- Returns:
- pbe key encryption method generator
-
pgpContentSignerBuilder
public abstract PGPContentSignerBuilder pgpContentSignerBuilder(int publicKeyAlgorithm, int hashAlgorithm) Return an instance ofPGPContentSignerBuilder
, which is responsible for providing concrete implementations needed for signature creation.- Parameters:
publicKeyAlgorithm
- the signing-keys public-key algorithmhashAlgorithm
- signature hash algorithm- Returns:
- content signer builder
-
pbeDataDecryptorFactory
public abstract PBEDataDecryptorFactory pbeDataDecryptorFactory(char[] messagePassphrase) throws PGPException Return an instance of thePBEDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages that were encrypted symmetrically with a passphrase.- Parameters:
messagePassphrase
- message passphrase- Returns:
- pbe data decryptor factory
- Throws:
PGPException
- if the factory cannot be instantiated
-
sessionKeyDataDecryptorFactory
public abstract SessionKeyDataDecryptorFactory sessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) Return an instance of theSessionKeyDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages using aPGPSessionKey
.- Parameters:
sessionKey
- session key- Returns:
- session-key data decryptor factory
-
publicKeyDataDecryptorFactory
public abstract PublicKeyDataDecryptorFactory publicKeyDataDecryptorFactory(PGPPrivateKey decryptionKey) Return an instance of thePublicKeyDataDecryptorFactory
, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages using aPGPPrivateKey
.- Parameters:
decryptionKey
- private decryption key- Returns:
- public-key data decryptor factory
-
pgpDigestCalculatorProvider
Return an instance of thePGPDigestCalculatorProvider
, which is responsible for providing concretePGPDigestCalculator
implementations.- Returns:
- pgp digest calculator provider
- Throws:
PGPException
- if the provider cannot be instantiated
-
pgpKeyPairGeneratorProvider
-
pgpContentSignerBuilderProvider
public abstract PGPContentSignerBuilderProvider pgpContentSignerBuilderProvider(int hashAlgorithmId) -
keyFingerPrintCalculator
-
pbeSecretKeyEncryptorFactory
public abstract PBESecretKeyEncryptorFactory pbeSecretKeyEncryptorFactory(boolean aead) throws PGPException - Throws:
PGPException
-
pbeSecretKeyEncryptorFactory
public abstract PBESecretKeyEncryptorFactory pbeSecretKeyEncryptorFactory(boolean aead, int symmetricKeyAlgorithm, int iterationCount) throws PGPException - Throws:
PGPException
-