Package zeroecho.sdk.guard
Class PasswordRecipient
java.lang.Object
zeroecho.sdk.guard.PasswordRecipient
- All Implemented Interfaces:
Recipient
Password recipient that derives a KEK via PBKDF2(HMAC-SHA-256) and wraps the
CEK with AES-GCM.
-
Constructor Summary
ConstructorsConstructorDescriptionPasswordRecipient(char[] password, int iterations, int saltLen, int kekBytes) Creates a password-based recipient.PasswordRecipient(char[] password, int iterations, int saltLen, int kekBytes, boolean decoy) Creates a password-based recipient that derives a key-encryption key (KEK) using PBKDF2. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]buildRecipientEntry(byte[] cek) Builds the recipient entry blob for this password recipient.booleandecoy()Returns whether this recipient entry is marked as a decoy.id()Returns the recipient entry identifier used in the header.
-
Constructor Details
-
PasswordRecipient
public PasswordRecipient(char[] password, int iterations, int saltLen, int kekBytes) Creates a password-based recipient.- Parameters:
password- the password; the caller should clear the array after useiterations- PBKDF2 iteration countsaltLen- salt length in byteskekBytes- derived KEK length in bytes- Throws:
NullPointerException- ifpasswordis null
-
PasswordRecipient
public PasswordRecipient(char[] password, int iterations, int saltLen, int kekBytes, boolean decoy) Creates a password-based recipient that derives a key-encryption key (KEK) using PBKDF2.The supplied password is expanded with PBKDF2 using the provided iteration count and a randomly generated salt of the specified length. The result is a KEK of the requested size in bytes, which is then used to wrap the content-encryption key (CEK) for this recipient. A recipient may also be marked as a decoy to obscure the actual number of usable recipients.
Security considerations
- The caller should clear the
passwordarray after constructing the recipient to minimize exposure in memory. - Choose an iteration count appropriate to the target platform to resist brute-force attacks.
- Decoy recipients increase confidentiality by hiding the number of real recipients but cannot successfully unwrap the CEK.
- Parameters:
password- the password used as input to PBKDF2; must not benulliterations- the PBKDF2 iteration countsaltLen- length of the random salt (in bytes)kekBytes- desired length of the derived KEK (in bytes)decoy-trueif this is a decoy recipient (fake entry that cannot unwrap a CEK);falseif it is a real recipient- Throws:
NullPointerException- ifpasswordisnull
- The caller should clear the
-
-
Method Details
-
id
Returns the recipient entry identifier used in the header. -
buildRecipientEntry
Builds the recipient entry blob for this password recipient.- Specified by:
buildRecipientEntryin interfaceRecipient- Parameters:
cek- the CEK to wrap- Returns:
- a blob containing
pack7(iter) || salt || wrapIv || wrappedCEK - Throws:
GeneralSecurityException- if PBKDF2 or AES-GCM failsIOException- if blob assembly 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.
-