Class PBEKeyEncryptionMethodGenerator
- java.lang.Object
-
- org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator
-
- org.bouncycastle.openpgp.operator.PBEKeyEncryptionMethodGenerator
-
- Direct Known Subclasses:
BcPBEKeyEncryptionMethodGenerator,JcePBEKeyEncryptionMethodGenerator
public abstract class PBEKeyEncryptionMethodGenerator extends PGPKeyEncryptionMethodGenerator
PGP style PBE encryption method.A pass phrase is used to generate an encryption key using the PGP
string-to-keymethod. This class always uses thesalted and iterated form of the S2K algorithm.Note that the iteration count provided to this method is a single byte as described by the
S2Kalgorithm, and the actual iteration count ranges exponentially from0x01== 1088 to0xFF== 65,011,712.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedPBEKeyEncryptionMethodGenerator(char[] passPhrase, PGPDigestCalculator s2kDigestCalculator)Construct a PBE key generator using the default iteration count (0x60== 65536 iterations).protectedPBEKeyEncryptionMethodGenerator(char[] passPhrase, PGPDigestCalculator s2kDigestCalculator, int s2kCount)Construct a PBE key generator using a specific iteration level.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract byte[]encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo)ContainedPacketgenerate(int encAlgorithm, byte[] sessionInfo)Generates a packet encoding the details of this encryption method.byte[]getKey(int encAlgorithm)Generate a key for a symmetric encryption algorithm using the PBE configuration in this method.PBEKeyEncryptionMethodGeneratorsetSecureRandom(java.security.SecureRandom random)Sets a user defined source of randomness.
-
-
-
Constructor Detail
-
PBEKeyEncryptionMethodGenerator
protected PBEKeyEncryptionMethodGenerator(char[] passPhrase, PGPDigestCalculator s2kDigestCalculator)Construct a PBE key generator using the default iteration count (0x60== 65536 iterations).- Parameters:
passPhrase- the pass phrase to encrypt with.s2kDigestCalculator- a digest calculator to use in the string-to-key function.
-
PBEKeyEncryptionMethodGenerator
protected PBEKeyEncryptionMethodGenerator(char[] passPhrase, PGPDigestCalculator s2kDigestCalculator, int s2kCount)Construct a PBE key generator using a specific iteration level.- Parameters:
passPhrase- the pass phrase to encrypt with.s2kDigestCalculator- a digest calculator to use in the string-to-key function.s2kCount- a single byteS2Kiteration count specifier, which is translated to an actual iteration count by the S2K class.
-
-
Method Detail
-
setSecureRandom
public PBEKeyEncryptionMethodGenerator setSecureRandom(java.security.SecureRandom random)
Sets a user defined source of randomness.If no SecureRandom is configured, a default SecureRandom will be used.
- Returns:
- the current generator.
-
getKey
public byte[] getKey(int encAlgorithm) throws PGPExceptionGenerate a key for a symmetric encryption algorithm using the PBE configuration in this method.- Parameters:
encAlgorithm- theencryption algorithmto generate the key for.- Returns:
- the bytes of the generated key.
- Throws:
PGPException- if an error occurs performing the string-to-key generation.
-
generate
public ContainedPacket generate(int encAlgorithm, byte[] sessionInfo) throws PGPException
Description copied from class:PGPKeyEncryptionMethodGeneratorGenerates a packet encoding the details of this encryption method.- Specified by:
generatein classPGPKeyEncryptionMethodGenerator- Parameters:
encAlgorithm- theencryption algorithmbeing usedsessionInfo- session data generated by the encrypted data generator.- Returns:
- a packet encoding the provided information and the configuration of this instance.
- Throws:
PGPException- if an error occurs constructing the packet.
-
encryptSessionInfo
protected abstract byte[] encryptSessionInfo(int encAlgorithm, byte[] key, byte[] sessionInfo) throws PGPException- Throws:
PGPException
-
-