Class KemCtxRecipient
- All Implemented Interfaces:
AutoCloseable, Recipient
KemContext encapsulation and uses it to wrap a content-encryption key
(CEK).
The workflow performed by this class is:
- Encapsulate with the given
KemContextto obtain a ciphertext and a shared secret. - Derive a KEK from the shared secret using HKDF-SHA256 with a random salt
and an
infostring bound to the algorithm identifier. - Generate a fresh IV and wrap the CEK under AES-GCM with the derived KEK.
- Serialize the components (KEM ciphertext, salt, IV, wrapped CEK) into a single byte array suitable for inclusion in a recipient entry.
Thread-safety
This class is not thread-safe. Each instance binds to a singleKemContext and must not be reused concurrently.- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionKemCtxRecipient(KemContext ctx, int kekBytes, int saltLen) Constructs a recipient that uses the given KEM context and parameters.KemCtxRecipient(KemContext ctx, int kekBytes, int saltLen, boolean decoy) Constructs a recipient that wraps content-encryption keys (CEKs) using the given KEM context and HKDF-based key derivation parameters. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buildRecipientEntry(byte[] cek) Builds a recipient entry for the given content-encryption key (CEK).voidclose()Closes the owned KEM context.booleandecoy()Returns whether this recipient entry is marked as a decoy.id()Returns the identifier string for this recipient mechanism.
-
Constructor Details
-
KemCtxRecipient
Constructs a recipient that uses the given KEM context and parameters.- Parameters:
ctx- the KEM context providing encapsulationkekBytes- KEK length; exactly 16 or 32 bytessaltLen- length of the random salt to apply during HKDF- Throws:
NullPointerException- ifctxisnullIllegalArgumentException- ifkekBytesis not exactly 16 or 32
-
KemCtxRecipient
Constructs a recipient that wraps content-encryption keys (CEKs) using the given KEM context and HKDF-based key derivation parameters.The KEM context performs encapsulation to derive a shared secret, which is expanded with HKDF into key-encryption key (KEK) material. The KEK is then used to wrap the CEK for this recipient. A recipient may also be flagged as a decoy to obscure the actual number of usable recipients.
- Parameters:
ctx- the KEM context responsible for performing encapsulation; must not benullkekBytes- KEK length; exactly 16 or 32 bytessaltLen- length in bytes of the random salt applied during HKDFdecoy-trueif this recipient is a decoy (fake entry that cannot unwrap a CEK);falseif it is a real recipient- Throws:
NullPointerException- ifctxisnullIllegalArgumentException- ifkekBytesis not exactly 16 or 32
-
-
Method Details
-
id
Returns the identifier string for this recipient mechanism.The format is
"KEM:<algoId>:GCM-WRAP"where<algoId>is taken from the underlyingKemContextalgorithm. -
buildRecipientEntry
Builds a recipient entry for the given content-encryption key (CEK).Encapsulates with the KEM context, derives a KEK, wraps the CEK, and serializes the structure into a binary entry. The returned value contains all material required for the recipient to later decapsulate and unwrap.
- Specified by:
buildRecipientEntryin interfaceRecipient- Parameters:
cek- the content-encryption key to be wrapped- Returns:
- encoded recipient entry containing encapsulation, salt, IV, and wrapped CEK
- Throws:
GeneralSecurityException- if encapsulation, KDF, or wrapping failsIOException- if an I/O error occurs during encoding
-
decoy
public boolean decoy()Returns whether this recipient entry is marked as a decoy.A decoy recipient is syntactically valid but intentionally unusable for recovering the content-encryption key (CEK). Such entries are included to conceal the number and identity of real recipients within a multi-recipient envelope.
-
close
Closes the owned KEM context.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- if context cleanup fails
-