Class SignEncryptResult
Contains the nested JWE(JWS) token produced by first signing the plaintext (creating JWS) then encrypting the JWS (creating JWE). This provides both authenticity (signature) and confidentiality (encryption) in a single operation.
Security Model
- Inner layer (JWS): Digital signature proves authenticity and integrity
- Outer layer (JWE): Encryption provides confidentiality
- Result: Confidential, authenticated, tamper-proof message
Token Structure
JWE( JWS(plaintext) )
Outer: BASE64URL(JWE Header).BASE64URL(Encrypted Key).BASE64URL(IV).BASE64URL(Ciphertext).BASE64URL(Tag)
Inner: BASE64URL(JWS Header).BASE64URL(Payload).BASE64URL(Signature)
Metadata Separation
The result provides separate metadata for the signing layer and encryption layer, allowing inspection of which keys and algorithms were used at each step.
Thread Safety
Instances are mutable during construction but should be treated as effectively immutable after being returned by SDK methods. Avoid invoking setters after receiving the result.
Example
SignEncryptResult result = sdk.signThenEncrypt(
"company-signing-key",
"partner-encryption-key",
sensitiveData
);
System.out.println("Sign-then-encrypt complete");
System.out.println("Signed with: " + result.getSignKeyRequested() +
" (" + result.getSignAlgorithmUsed() + ")"
+ " material version " + result.getSignMaterialVersion());
System.out.println("Encrypted with: " + result.getEncryptKeyRequested() +
" (" + result.getEncryptAlgorithmUsed() + ")"
+ " material version " + result.getEncryptMaterialVersion());
// Send to partner
String protectedMessage = result.getJweToken();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the algorithm used for encryption.Gets the key identifier requested for encryption.Gets the key-material version (ank_kv) that performed the encryption operation under the requested Stable KID.Gets structured warnings related to the encryption operation.Returns the nested JWE(JWS) token.Gets the algorithm used for signing.Gets the key identifier requested for signing.Gets the key-material version (ank_kv) that performed the signing operation under the requested Stable KID.Gets structured warnings related to the signing operation.booleanChecks if there are any warnings (sign or encrypt).booleanChecks if encryption operation produced warnings.booleanChecks if signing operation produced warnings.setEncryptAlgorithmUsed(String encryptAlgorithmUsed) Sets the algorithm used for encryption.setEncryptKeyRequested(String encryptKeyRequested) Sets the key identifier requested for encryption.setEncryptMaterialVersion(Integer encryptMaterialVersion) Sets the key-material version that performed the encryption operation.setEncryptWarnings(List<CryptoWarning> encryptWarnings) Sets warnings related to the encryption operation.setJweToken(String jweToken) Sets the nested JWE(JWS) token.setSignAlgorithmUsed(String signAlgorithmUsed) Sets the algorithm used for signing.setSignKeyRequested(String signKeyRequested) Sets the key identifier requested for signing.setSignMaterialVersion(Integer signMaterialVersion) Sets the key-material version that performed the signing operation.setSignWarnings(List<CryptoWarning> signWarnings) Sets warnings related to the signing operation.toString()Returns string representation for debugging.
-
Constructor Details
-
SignEncryptResult
public SignEncryptResult()Default constructor initializing empty warning lists.
-
-
Method Details
-
getJweToken
Returns the nested JWE(JWS) token.The outer layer is a JWE (encrypted), and the inner layer is a JWS (signed). Only the holder of the decryption key can access the inner signed payload.
- Returns:
- compact JWE token containing encrypted JWS; never
null
-
setJweToken
Sets the nested JWE(JWS) token.- Parameters:
jweToken- the token- Returns:
- this instance for fluent API
-
getSignKeyRequested
Gets the key identifier requested for signing.- Returns:
- requested sign key ID
-
setSignKeyRequested
Sets the key identifier requested for signing.- Parameters:
signKeyRequested- the key ID- Returns:
- this instance for fluent API
-
getSignMaterialVersion
Gets the key-material version (ank_kv) that performed the signing operation under the requested Stable KID.- Returns:
- sign material version;
nullwhen not resolvable — never 0
-
setSignMaterialVersion
Sets the key-material version that performed the signing operation.- Parameters:
signMaterialVersion- the material version- Returns:
- this instance for fluent API
-
getSignAlgorithmUsed
Gets the algorithm used for signing.Example: "ML-DSA-87", "ECDSA-P256-SHA256"
- Returns:
- signature algorithm
-
setSignAlgorithmUsed
Sets the algorithm used for signing.- Parameters:
signAlgorithmUsed- the algorithm- Returns:
- this instance for fluent API
-
getSignWarnings
Gets structured warnings related to the signing operation.Warnings are type-safe instances allowing pattern matching:
for (CryptoWarning warning : result.getSignWarnings()) { switch (warning) { case KeyExpirationWarning kew when kew.severity() == WarningSeverity.CRITICAL -> rotateSigningKey(); case UsageLimitWarning ulw -> logger.warn("Signing key usage: {}", ulw.message()); case GenericWarning gw -> logger.info("Sign warning: {}", gw.rawMessage()); } }- Returns:
- unmodifiable list of sign warnings (never null, may be empty)
-
setSignWarnings
Sets warnings related to the signing operation.- Parameters:
signWarnings- the warnings- Returns:
- this instance for fluent API
-
getEncryptKeyRequested
Gets the key identifier requested for encryption.- Returns:
- requested encrypt key ID
-
setEncryptKeyRequested
Sets the key identifier requested for encryption.- Parameters:
encryptKeyRequested- the key ID- Returns:
- this instance for fluent API
-
getEncryptMaterialVersion
Gets the key-material version (ank_kv) that performed the encryption operation under the requested Stable KID.- Returns:
- encrypt material version;
nullwhen not resolvable — never 0
-
setEncryptMaterialVersion
Sets the key-material version that performed the encryption operation.- Parameters:
encryptMaterialVersion- the material version- Returns:
- this instance for fluent API
-
getEncryptAlgorithmUsed
Gets the algorithm used for encryption.Example: "ML-KEM-1024+A256GCM", "RSA-OAEP-256+A256GCM"
- Returns:
- encryption algorithm
-
setEncryptAlgorithmUsed
Sets the algorithm used for encryption.- Parameters:
encryptAlgorithmUsed- the algorithm- Returns:
- this instance for fluent API
-
getEncryptWarnings
Gets structured warnings related to the encryption operation.Warnings are type-safe instances allowing pattern matching:
for (CryptoWarning warning : result.getEncryptWarnings()) { switch (warning) { case KeyExpirationWarning kew when kew.daysRemaining() <= 14 -> scheduleKeyRotation(kew.daysRemaining()); case UsageLimitWarning ulw -> logger.warn("Encryption key usage: {}", ulw.message()); case GenericWarning gw -> logger.info("Encrypt warning: {}", gw.rawMessage()); } }- Returns:
- unmodifiable list of encrypt warnings (never null, may be empty)
-
setEncryptWarnings
Sets warnings related to the encryption operation.- Parameters:
encryptWarnings- the warnings- Returns:
- this instance for fluent API
-
hasAnyWarnings
public boolean hasAnyWarnings()Checks if there are any warnings (sign or encrypt).- Returns:
- true if either signing or encryption produced warnings
-
hasSignWarnings
public boolean hasSignWarnings()Checks if signing operation produced warnings.- Returns:
- true if sign warnings list is non-empty
-
hasEncryptWarnings
public boolean hasEncryptWarnings()Checks if encryption operation produced warnings.- Returns:
- true if encrypt warnings list is non-empty
-
toString
Returns string representation for debugging.
-