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 OpenPGPImplementationReturn the currently setOpenPGPImplementationinstance.abstract KeyFingerPrintCalculatorabstract PBEDataDecryptorFactorypbeDataDecryptorFactory(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 PBEKeyEncryptionMethodGeneratorpbeKeyEncryptionMethodGenerator(char[] messagePassphrase) Return an instance ofPBEKeyEncryptionMethodGeneratorwhich is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.SALTED_AND_ITERATEDmode.abstract PBEKeyEncryptionMethodGeneratorpbeKeyEncryptionMethodGenerator(char[] messagePassphrase, S2K.Argon2Params argon2Params) Return an instance ofPBEKeyEncryptionMethodGeneratorwhich is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.ARGON_2mode.abstract PBESecretKeyDecryptorBuilderProviderReturn an instance ofPBESecretKeyDecryptorBuilderProviderwhich is responsible for providing implementations needed for secret key unlocking.abstract PBESecretKeyEncryptorFactorypbeSecretKeyEncryptorFactory(boolean aead) abstract PBESecretKeyEncryptorFactorypbeSecretKeyEncryptorFactory(boolean aead, int symmetricKeyAlgorithm, int iterationCount) abstract PGPContentSignerBuilderpgpContentSignerBuilder(int publicKeyAlgorithm, int hashAlgorithm) Return an instance ofPGPContentSignerBuilder, which is responsible for providing concrete implementations needed for signature creation.abstract PGPContentSignerBuilderProviderpgpContentSignerBuilderProvider(int hashAlgorithmId) abstract PGPContentVerifierBuilderProviderReturn an instance ofPGPContentVerifierBuilderProviderwhich is responsible for providing implementations needed for signature verification.abstract PGPDataEncryptorBuilderpgpDataEncryptorBuilder(int symmetricKeyAlgorithm) Return an instance ofPGPDataEncryptorBuilderwhich is responsible for providing implementations needed for creating encrypted data packets.abstract PGPDigestCalculatorProviderReturn an instance of thePGPDigestCalculatorProvider, which is responsible for providing concretePGPDigestCalculatorimplementations.abstract PGPKeyPairGeneratorProviderabstract PGPObjectFactorypgpObjectFactory(InputStream packetInputStream) Return an instance ofPGPObjectFactorybased on the givenInputStream.policy()abstract PublicKeyDataDecryptorFactorypublicKeyDataDecryptorFactory(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 ofPublicKeyKeyEncryptionMethodGeneratorwhich is responsible for creating public-key-based encryptors for OpenPGP messages.abstract SessionKeyDataDecryptorFactorysessionKeyDataDecryptorFactory(PGPSessionKey sessionKey) Return an instance of theSessionKeyDataDecryptorFactory, which is responsible for providing concrete implementations needed to decrypt OpenPGP messages using aPGPSessionKey.static voidsetInstance(OpenPGPImplementation implementation) Replace theOpenPGPImplementationinstance that is returned bygetInstance().setPolicy(OpenPGPPolicy policy)
-
Constructor Details
-
OpenPGPImplementation
public OpenPGPImplementation()
-
-
Method Details
-
setInstance
Replace theOpenPGPImplementationinstance that is returned bygetInstance().- Parameters:
implementation- instance
-
getInstance
Return the currently setOpenPGPImplementationinstance. The default isBcOpenPGPImplementation.- Returns:
- instance
-
policy
-
setPolicy
-
pgpObjectFactory
Return an instance ofPGPObjectFactorybased on the givenInputStream.- Parameters:
packetInputStream- packet input stream- Returns:
- object factory
-
pgpContentVerifierBuilderProvider
Return an instance ofPGPContentVerifierBuilderProviderwhich is responsible for providing implementations needed for signature verification.- Returns:
- content verifier builder provider
-
pbeSecretKeyDecryptorBuilderProvider
Return an instance ofPBESecretKeyDecryptorBuilderProviderwhich is responsible for providing implementations needed for secret key unlocking.- Returns:
- secret key decryptor builder provider
-
pgpDataEncryptorBuilder
Return an instance ofPGPDataEncryptorBuilderwhich 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 ofPublicKeyKeyEncryptionMethodGeneratorwhich 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 ofPBEKeyEncryptionMethodGeneratorwhich is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.SALTED_AND_ITERATEDmode. 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 ofPBEKeyEncryptionMethodGeneratorwhich is responsible for creating symmetric-key-based encryptors for OpenPGP messages, usingS2K.ARGON_2mode. 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 concretePGPDigestCalculatorimplementations.- 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
-