Class JcePGPDataEncryptorBuilder
- java.lang.Object
-
- org.bouncycastle.openpgp.operator.jcajce.JcePGPDataEncryptorBuilder
-
- All Implemented Interfaces:
PGPDataEncryptorBuilder
public class JcePGPDataEncryptorBuilder extends java.lang.Object implements PGPDataEncryptorBuilder
PGPDataEncryptorBuilderimplementation that sources cryptographic primitives using the JCE APIs.By default, cryptographic primitives will be loaded using the default JCE load order (i.e. without specifying a provider). A specific provider can be specified using one of the
setProvider(String)methods.
-
-
Constructor Summary
Constructors Constructor Description JcePGPDataEncryptorBuilder(int encAlgorithm)Constructs a new data encryptor builder for a specified cipher type.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description PGPDataEncryptorbuild(byte[] keyBytes)Builds a data encryptor using the algorithm configured for this builder.intgetAlgorithm()The encryption algorithm used by data encryptors created by this builder.java.security.SecureRandomgetSecureRandom()Gets the SecureRandom instance used by this builder.JcePGPDataEncryptorBuildersetProvider(java.lang.String providerName)Sets the JCE provider to source cryptographic primitives from.JcePGPDataEncryptorBuildersetProvider(java.security.Provider provider)Sets the JCE provider to source cryptographic primitives from.JcePGPDataEncryptorBuildersetSecureRandom(java.security.SecureRandom random)Provide a user defined source of randomness.JcePGPDataEncryptorBuildersetWithIntegrityPacket(boolean withIntegrityPacket)Sets whether or not the resulting encrypted data will be protected using an integrity packet.
-
-
-
Constructor Detail
-
JcePGPDataEncryptorBuilder
public JcePGPDataEncryptorBuilder(int encAlgorithm)
Constructs a new data encryptor builder for a specified cipher type.- Parameters:
encAlgorithm- one of thesupported symmetric cipher algorithms. May not beSymmetricKeyAlgorithmTags.NULL.
-
-
Method Detail
-
setWithIntegrityPacket
public JcePGPDataEncryptorBuilder setWithIntegrityPacket(boolean withIntegrityPacket)
Sets whether or not the resulting encrypted data will be protected using an integrity packet.- Parameters:
withIntegrityPacket- true if an integrity packet is to be included, false otherwise.- Returns:
- the current builder.
-
setProvider
public JcePGPDataEncryptorBuilder setProvider(java.security.Provider provider)
Sets the JCE provider to source cryptographic primitives from.- Parameters:
provider- the JCE provider to use.- Returns:
- the current builder.
-
setProvider
public JcePGPDataEncryptorBuilder setProvider(java.lang.String providerName)
Sets the JCE provider to source cryptographic primitives from.- Parameters:
providerName- the name of the JCE provider to use.- Returns:
- the current builder.
-
setSecureRandom
public JcePGPDataEncryptorBuilder setSecureRandom(java.security.SecureRandom random)
Provide a user defined source of randomness.If no SecureRandom is configured, a default SecureRandom will be used.
- Parameters:
random- the secure random to be used.- Returns:
- the current builder.
-
getAlgorithm
public int getAlgorithm()
Description copied from interface:PGPDataEncryptorBuilderThe encryption algorithm used by data encryptors created by this builder.- Specified by:
getAlgorithmin interfacePGPDataEncryptorBuilder- Returns:
- one of the
symmetric encryption algorithms.
-
getSecureRandom
public java.security.SecureRandom getSecureRandom()
Description copied from interface:PGPDataEncryptorBuilderGets the SecureRandom instance used by this builder.If a SecureRandom has not been explicitly configured, a default
SecureRandomis constructed and retained by the this builder.- Specified by:
getSecureRandomin interfacePGPDataEncryptorBuilder
-
build
public PGPDataEncryptor build(byte[] keyBytes) throws PGPException
Description copied from interface:PGPDataEncryptorBuilderBuilds a data encryptor using the algorithm configured for this builder.- Specified by:
buildin interfacePGPDataEncryptorBuilder- Parameters:
keyBytes- the bytes of the key to use for the cipher.- Returns:
- a data encryptor with an initialised cipher.
- Throws:
PGPException- if an error occurs initialising the configured encryption.
-
-