Class PBESecretKeyEncryptor
java.lang.Object
org.bouncycastle.openpgp.operator.PBESecretKeyEncryptor
Class responsible for encrypting secret key material or data packets using a passphrase.
RFC9580 recommends the following S2K specifiers + usages:
| S2K Specifier | S2K Usage | Note |
|---|---|---|
S2K.ARGON_2 |
SecretKeyPacket.USAGE_AEAD |
RECOMMENDED; Argon2 MUST be used with AEAD |
S2K.SALTED_AND_ITERATED |
SecretKeyPacket.USAGE_SHA1 |
MAY be used if Argon2 is not available; Take care to use high octet count + strong passphrase |
| none | SecretKeyPacket.USAGE_NONE |
Unprotected |
Additionally, implementations MAY use the following combinations with caution:
| S2K Specifier | S2K Usage | Note |
|---|---|---|
S2K.SALTED_AND_ITERATED |
SecretKeyPacket.USAGE_AEAD |
Does not provide memory hardness |
S2K.SIMPLE |
SecretKeyPacket.USAGE_SHA1 |
Only for reading secret keys in backwards compatibility mode |
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected intprotected intprotected char[]protected SecureRandomprotected S2Kprotected intprotected PGPDigestCalculator -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedPBESecretKeyEncryptor(int encAlgorithm, int aeadAlgorithm, S2K.Argon2Params argon2Params, SecureRandom random, char[] passPhrase) protectedPBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, int s2kCount, SecureRandom random, char[] passPhrase) protectedPBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, SecureRandom random, char[] passPhrase) -
Method Summary
Modifier and TypeMethodDescriptionbyte[]encryptKeyData(byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen) Encrypt the passed in keyData using the key and the iv provided.abstract byte[]encryptKeyData(byte[] key, byte[] keyData, int keyOff, int keyLen) byte[]encryptKeyData(byte[] keyData, int keyOff, int keyLen) Key encryption method invoked for V4 keys and greater.intintabstract byte[]intbyte[]getKey()getS2K()
-
Field Details
-
encAlgorithm
protected int encAlgorithm -
aeadAlgorithm
protected int aeadAlgorithm -
passPhrase
protected char[] passPhrase -
s2kDigestCalculator
-
s2kCount
protected int s2kCount -
s2k
-
random
-
-
Constructor Details
-
PBESecretKeyEncryptor
protected PBESecretKeyEncryptor(int encAlgorithm, int aeadAlgorithm, S2K.Argon2Params argon2Params, SecureRandom random, char[] passPhrase) -
PBESecretKeyEncryptor
protected PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, SecureRandom random, char[] passPhrase) -
PBESecretKeyEncryptor
protected PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, int s2kCount, SecureRandom random, char[] passPhrase)
-
-
Method Details
-
getAlgorithm
public int getAlgorithm() -
getAeadAlgorithm
public int getAeadAlgorithm() -
getHashAlgorithm
public int getHashAlgorithm() -
getKey
- Throws:
PGPException
-
getS2K
-
encryptKeyData
Key encryption method invoked for V4 keys and greater.- Parameters:
keyData- raw key datakeyOff- offset into raw key datakeyLen- length of key data to use.- Returns:
- an encryption of the passed in keyData.
- Throws:
PGPException- on error in the underlying encryption process.
-
encryptKeyData
public abstract byte[] encryptKeyData(byte[] key, byte[] keyData, int keyOff, int keyLen) throws PGPException - Throws:
PGPException
-
encryptKeyData
public byte[] encryptKeyData(byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen) throws PGPException Encrypt the passed in keyData using the key and the iv provided.This method is only used for processing version 3 keys.
- Throws:
PGPException
-
getCipherIV
public abstract byte[] getCipherIV()
-