Class EncCtxRecipient
- All Implemented Interfaces:
AutoCloseable, Recipient
EncryptionContext.
Unlike KemCtxRecipient, which derives a key-encryption key (KEK) via
key encapsulation, this class directly uses an existing
EncryptionContext to transform the CEK into a wrapped form. The CEK
is streamed through the context, and the transformed output is returned as a
recipient entry.
Thread-safety
This class is not thread-safe. Each instance binds to a singleEncryptionContext and must not be reused concurrently.- Since:
- 1.0
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a recipient that uses the givenEncryptionContext.EncCtxRecipient(EncryptionContext enc, boolean decoy) Constructs a recipient backed by the specifiedEncryptionContext. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buildRecipientEntry(byte[] cek) Builds a recipient entry for the given content-encryption key (CEK).voidclose()Closes the owned encryption context.booleandecoy()Returns whether this recipient entry is marked as a decoy.id()Returns the identifier string for this recipient mechanism.
-
Constructor Details
-
EncCtxRecipient
Constructs a recipient that uses the givenEncryptionContext.- Parameters:
enc- the encryption context used to wrap CEKs
-
EncCtxRecipient
Constructs a recipient backed by the specifiedEncryptionContext.The provided encryption context is used to wrap content-encryption keys (CEKs) for this recipient. A recipient may also be marked as a decoy to obscure the number of real recipients in a multi-recipient envelope.
- Parameters:
enc- the encryption context used to perform CEK wrapping; must not benulldecoy-trueif this recipient is a decoy entry (fake recipient that cannot unwrap a CEK),falseif it is a real recipient
-
-
Method Details
-
id
Returns the identifier string for this recipient mechanism.The format is
"CTX-ENC:<algoId>"where<algoId>is the canonical identifier of the underlyingEncryptionContextalgorithm. -
buildRecipientEntry
Builds a recipient entry for the given content-encryption key (CEK).The CEK bytes are streamed through the attached
EncryptionContext, and the encrypted result is returned. The resulting byte array represents the recipient entry that can later be processed for decryption with the corresponding context.- Specified by:
buildRecipientEntryin interfaceRecipient- Parameters:
cek- the content-encryption key to wrap- Returns:
- the wrapped CEK encoded as a recipient entry
- Throws:
IOException- if streaming through the encryption context fails
-
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 encryption context.- Specified by:
closein interfaceAutoCloseable- Throws:
IOException- if context cleanup fails
-