Top Description Fields Constructors Methods
org.bouncycastle.openpgp.operator

public abstract Class PBESecretKeyEncryptor

extends Object
Class Inheritance
Imports
java.security.SecureRandom, org.bouncycastle.bcpg.S2K, org.bouncycastle.openpgp.PGPException

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 org.bouncycastle.bcpg.SecretKeyPacket#USAGE_AEAD RECOMMENDED; Argon2 MUST be used with AEAD
S2K#SALTED_AND_ITERATED org.bouncycastle.bcpg.SecretKeyPacket#USAGE_SHA1 MAY be used if Argon2 is not available; Take care to use high octet count + strong passphrase
none org.bouncycastle.bcpg.SecretKeyPacket#USAGE_NONE Unprotected

Additionally, implementations MAY use the following combinations with caution:

S2K Specifier S2K Usage Note
S2K#SALTED_AND_ITERATED org.bouncycastle.bcpg.SecretKeyPacket#USAGE_AEAD Does not provide memory hardness
S2K#SIMPLE org.bouncycastle.bcpg.SecretKeyPacket#USAGE_SHA1 Only for reading secret keys in backwards compatibility mode

Field Summary

Modifier and TypeField and Description
protected int
protected int
protected char[]
protected SecureRandom
protected S2K
protected int
protected PGPDigestCalculator

Constructor Summary

AccessConstructor and Description
protected
PBESecretKeyEncryptor(int encAlgorithm, int aeadAlgorithm, S2K.Argon2Params argon2Params, SecureRandom random, char[] passPhrase)

protected
PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, SecureRandom random, char[] passPhrase)

protected
PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, int s2kCount, SecureRandom random, char[] passPhrase)

Method Summary

Modifier and TypeMethod and Description
public byte[]

Returns:

an encryption of the passed in keyData.
encryptKeyData
(byte[]
raw key data
keyData
,
int
offset into raw key data
keyOff
,
int
length of key data to use.
keyLen
)

Key encryption method invoked for V4 keys and greater.

public abstract byte[]
encryptKeyData(byte[] key, byte[] keyData, int keyOff, int keyLen)

public byte[]
encryptKeyData(byte[] key, byte[] iv, byte[] keyData, int keyOff, int keyLen)

Encrypt the passed in keyData using the key and the iv provided.

public int
public int
public abstract byte[]
public int
public byte[]
public S2K
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

aeadAlgorithmback to summary
protected int aeadAlgorithm
encAlgorithmback to summary
protected int encAlgorithm
passPhraseback to summary
protected char[] passPhrase
randomback to summary
protected SecureRandom random
s2kback to summary
protected S2K s2k
s2kCountback to summary
protected int s2kCount
s2kDigestCalculatorback to summary
protected PGPDigestCalculator s2kDigestCalculator

Constructor Detail

PBESecretKeyEncryptorback to summary
protected PBESecretKeyEncryptor(int encAlgorithm, int aeadAlgorithm, S2K.Argon2Params argon2Params, SecureRandom random, char[] passPhrase)
PBESecretKeyEncryptorback to summary
protected PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, SecureRandom random, char[] passPhrase)
PBESecretKeyEncryptorback to summary
protected PBESecretKeyEncryptor(int encAlgorithm, PGPDigestCalculator s2kDigestCalculator, int s2kCount, SecureRandom random, char[] passPhrase)

Method Detail

encryptKeyDataback to summary
public byte[] encryptKeyData(byte[] keyData, int keyOff, int keyLen) throws PGPException

Key encryption method invoked for V4 keys and greater.

Parameters
keyData:byte[]

raw key data

keyOff:int

offset into raw key data

keyLen:int

length of key data to use.

Returns:byte[]

an encryption of the passed in keyData.

Exceptions
PGPException:
on error in the underlying encryption process.
encryptKeyDataback to summary
public abstract byte[] encryptKeyData(byte[] key, byte[] keyData, int keyOff, int keyLen) throws PGPException
encryptKeyDataback to summary
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.

getAeadAlgorithmback to summary
public int getAeadAlgorithm()
getAlgorithmback to summary
public int getAlgorithm()
getCipherIVback to summary
public abstract byte[] getCipherIV()
getHashAlgorithmback to summary
public int getHashAlgorithm()
getKeyback to summary
public byte[] getKey() throws PGPException
getS2Kback to summary
public S2K getS2K()