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

public abstract Class PublicKeyKeyEncryptionMethodGenerator

extends Object
implements PGPKeyEncryptionMethodGenerator
Class Inheritance
All Implemented Interfaces
org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator
Known Direct Subclasses
org.bouncycastle.openpgp.operator.bc.BcPublicKeyKeyEncryptionMethodGenerator, org.bouncycastle.openpgp.operator.jcajce.JcePublicKeyKeyEncryptionMethodGenerator
Imports
org.bouncycastle.bcpg.ContainedPacket, .MPInteger, .PublicKeyAlgorithmTags, .PublicKeyEncSessionPacket, org.bouncycastle.openpgp.PGPException, .PGPPublicKey, org.bouncycastle.util.Properties, java.io.IOException, java.math.BigInteger

Abstract generator class for encryption methods that produce PKESK (public-key encrypted session key) packets. PKESKs are used when encrypting a message for a recipients public key. The purpose of this class is to allow subclasses to decide, which implementation to use.

Field Summary

Modifier and TypeField and Description
private final PGPPublicKey
public static final String
protected boolean
protected boolean
public static final long
WILDCARD

Deprecated use WILDCARD_KEYID
public static final byte[]
public static final long

Constructor Summary

AccessConstructor and Description
protected

Method Summary

Modifier and TypeMethod and Description
private void
addCheckSum(byte[] sessionInfo, int pos)

private byte[]
convertToEncodedMPI(byte[] encryptedSessionInfo)

protected byte[]
createSessionInfo(byte algorithm, byte[] keyBytes)

public byte[][]
encodeEncryptedSessionInfo(byte[] encryptedSessionInfo)

protected abstract byte[]

Returns:

encrypted session info
encryptSessionInfo
(PGPPublicKey
recipients public key
pubKey
,
byte[]
session-key
sessionKey
,
byte
for v3: session key algorithm ID; for v6: 0
symAlgId
,
boolean isV3)

Encrypt a session key using the recipients public key.

public ContainedPacket

Returns:

PKESKv6 or v3 packet
generate
(PGPDataEncryptorBuilder dataEncryptorBuilder, byte[]
session-key algorithm id + session-key + checksum
sessionKey
)

Implements org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator.generate.

Generate a Public-Key Encrypted Session-Key (PKESK) packet of version 3.

protected static byte[]
getSessionInfo(byte[] ephPubEncoding, byte optSymKeyAlgorithm, byte[] wrappedSessionKey)

private static boolean
public PublicKeyKeyEncryptionMethodGenerator

Returns:

the current generator.
setSessionKeyObfuscation
(boolean enabled)

Controls whether to obfuscate the size of ECDH session keys using extra padding where necessary.

public PublicKeyKeyEncryptionMethodGenerator

Returns:

this
setUseWildcardKeyID
(boolean
boolean
enabled
)
Deprecated use setUseWildcardRecipient(boolean) instead TODO: Remove in a future release

Controls whether the recipient key ID/fingerprint is hidden (replaced by a wildcard value).

public PublicKeyKeyEncryptionMethodGenerator

Returns:

this
setUseWildcardRecipient
(boolean
boolean
enabled
)

Controls whether the recipient key ID/fingerprint is hidden (replaced by a wildcard value).

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

pubKeyback to summary
private final PGPPublicKey pubKey
SESSION_KEY_OBFUSCATION_PROPERTYback to summary
public static final String SESSION_KEY_OBFUSCATION_PROPERTY
sessionKeyObfuscationback to summary
protected boolean sessionKeyObfuscation
useWildcardRecipientback to summary
protected boolean useWildcardRecipient
WILDCARDback to summary
public static final long WILDCARD

Deprecated

use WILDCARD_KEYID

WILDCARD_FINGERPRINTback to summary
public static final byte[] WILDCARD_FINGERPRINT
WILDCARD_KEYIDback to summary
public static final long WILDCARD_KEYID

Constructor Detail

PublicKeyKeyEncryptionMethodGeneratorback to summary
protected PublicKeyKeyEncryptionMethodGenerator(PGPPublicKey pubKey)

Method Detail

addCheckSumback to summary
private void addCheckSum(byte[] sessionInfo, int pos)
convertToEncodedMPIback to summary
private byte[] convertToEncodedMPI(byte[] encryptedSessionInfo) throws PGPException
createSessionInfoback to summary
protected byte[] createSessionInfo(byte algorithm, byte[] keyBytes)
encodeEncryptedSessionInfoback to summary
public byte[][] encodeEncryptedSessionInfo(byte[] encryptedSessionInfo) throws PGPException
encryptSessionInfoback to summary
protected abstract byte[] encryptSessionInfo(PGPPublicKey pubKey, byte[] sessionKey, byte symAlgId, boolean isV3) throws PGPException

Encrypt a session key using the recipients public key.

Parameters
pubKey:PGPPublicKey

recipients public key

sessionKey:byte[]

session-key

symAlgId:byte

for v3: session key algorithm ID; for v6: 0

Returns:byte[]

encrypted session info

generateback to summary
public ContainedPacket generate(PGPDataEncryptorBuilder dataEncryptorBuilder, byte[] sessionKey) throws PGPException

Implements org.bouncycastle.openpgp.operator.PGPKeyEncryptionMethodGenerator.generate.

Generate a Public-Key Encrypted Session-Key (PKESK) packet of version 3. PKESKv3 packets are used with Symmetrically-Encrypted-Integrity-Protected Data (SEIPD) packets of version 1 or with Symmetrically-Encrypted Data (SED) packets and MUST NOT be used with SEIPDv2 packets. PKESKv3 packets are used with keys that do not support org.bouncycastle.bcpg.sig.Features#FEATURE_SEIPD_V2 or as a fallback.

Generate a Public-Key Encrypted Session-Key (PKESK) packet of version 6. PKESKv6 packets are used with Symmetrically-Encrypted Integrity-Protected Data (SEIPD) packets of version 2 only. PKESKv6 packets are used with keys that support org.bouncycastle.bcpg.sig.Features#FEATURE_SEIPD_V2.

Parameters
sessionKey:byte[]

session-key algorithm id + session-key + checksum

Returns:ContainedPacket

PKESKv6 or v3 packet

Exceptions
PGPException:
if the PKESK packet cannot be generated
See Also
RFC9580 - Version 6 Public Key Encrypted Session Key Packet, RFC9580 - Version 3 Public Key Encrypted Session Key Packet
getSessionInfoback to summary
protected static byte[] getSessionInfo(byte[] ephPubEncoding, byte optSymKeyAlgorithm, byte[] wrappedSessionKey)
getSessionKeyObfuscationDefaultback to summary
private static boolean getSessionKeyObfuscationDefault()
setSessionKeyObfuscationback to summary
public PublicKeyKeyEncryptionMethodGenerator setSessionKeyObfuscation(boolean enabled)

Controls whether to obfuscate the size of ECDH session keys using extra padding where necessary.

The default behaviour can be configured using the system property "org.bouncycastle.openpgp.session_key_obfuscation", or else it will default to enabled.

Returns:PublicKeyKeyEncryptionMethodGenerator

the current generator.

setUseWildcardKeyIDback to summary
public PublicKeyKeyEncryptionMethodGenerator setUseWildcardKeyID(boolean enabled)

Deprecated

use setUseWildcardRecipient(boolean) instead TODO: Remove in a future release

Controls whether the recipient key ID/fingerprint is hidden (replaced by a wildcard value).

Parameters
enabled:boolean

boolean

Returns:PublicKeyKeyEncryptionMethodGenerator

this

Annotations
@Deprecated
setUseWildcardRecipientback to summary
public PublicKeyKeyEncryptionMethodGenerator setUseWildcardRecipient(boolean enabled)

Controls whether the recipient key ID/fingerprint is hidden (replaced by a wildcard value).

Parameters
enabled:boolean

boolean

Returns:PublicKeyKeyEncryptionMethodGenerator

this