Class DecryptVerifyResult
Contains the plaintext extracted after decrypting a nested JWE(JWS) token and
verifying the inner JWS signature. This is the inverse of
signThenEncrypt.
Security Model
- Step 1: Decrypt outer JWE layer to reveal inner JWS
- Step 2: Verify inner JWS signature for authenticity
- Result: Verified plaintext with sender authentication
Critical: Signature Validation
ALWAYS check isSignatureValid() before trusting the plaintext.
Decryption can succeed even if the signature is invalid, which may indicate tampering
or forgery.
Metadata Separation
The result provides separate metadata for the decryption layer and verification layer, allowing inspection of which keys and algorithms were used at each step.
Streaming Variant
The buffered
decryptThenVerifyFileStream
variant writes the verified plaintext directly to the destination file (bounded memory, never
buffered in the result), so on that path getDecryptedData() is null even though
isSignatureValid() is true — the isSignatureValid → getDecryptedData idiom
shown above applies to the in-memory paths (decryptThenVerify). The streaming path additionally surfaces the two integrity dimensions via
getGcmTagVerdict() / getSignatureVerdict().
Thread Safety
Instances are mutable during construction but should be treated as effectively immutable after being returned by SDK methods.
Example
DecryptVerifyResult result = sdk.decryptThenVerify(jweToken);
if (result.isSignatureValid()) {
byte[] plaintext = result.getDecryptedData();
System.out.println("Message verified from: " + result.getSigningKey());
System.out.println("Content: " + new String(plaintext, StandardCharsets.UTF_8));
} else {
System.out.println("WARNING: Signature invalid - do not trust this message");
// Log security incident
}
// Inspect metadata
System.out.println("Decrypted with: " + result.getDecryptKeyRequested()
+ " material version " + result.getDecryptMaterialVersion());
System.out.println("Signature algorithm: " + result.getSignAlgorithmUsed());
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionGets the algorithm used for decryption.byte[]Returns the decrypted plaintext bytes.Gets the key identifier requested for decryption.Gets the key-material version (ank_kv) that performed the decryption under the requested Stable KID.Gets structured warnings related to the decryption operation.Returns the outer AES-GCM tag integrity dimension of the streaming decrypt-verify result.Returns the embedded RFC 3161 qualified timestamp from the inner JWS, when present.Gets the algorithm used for signing (from JWS header).Returns the inner JWS signature integrity dimension of the streaming decrypt-verify result.Gets additional signer information (if present in JWS claims).Gets the key identifier used for signing (from JWS header).Gets the key-material version (ank_kv) that performed the signature verification under the requested Stable KID.Gets structured warnings related to the signature verification operation.booleanChecks if there are any warnings (decrypt or verify).booleanChecks if decryption operation produced warnings.booleanChecks if verification operation produced warnings.booleanChecks if operation completed successfully with no issues.booleanChecks if the signature verification succeeded.setDecryptAlgorithmUsed(String decryptAlgorithmUsed) Sets the algorithm used for decryption.setDecryptedData(byte[] decryptedData) Sets the decrypted plaintext bytes.setDecryptKeyRequested(String decryptKeyRequested) Sets the key identifier requested for decryption.setDecryptMaterialVersion(Integer decryptMaterialVersion) Sets the key-material version that performed the decryption.setDecryptWarnings(List<CryptoWarning> decryptWarnings) Sets warnings related to the decryption operation.setGcmTagVerdict(String gcmTagVerdict) Sets the outer AES-GCM tag integrity dimension.setQualifiedTimestamp(QualifiedTimestampInfo qualifiedTimestamp) Sets the embedded qualified timestamp from the inner JWS.setSignAlgorithmUsed(String signAlgorithmUsed) Sets the algorithm used for signing.setSignatureValid(boolean signatureValid) Sets whether signature verification succeeded.setSignatureVerdict(String signatureVerdict) Sets the inner JWS signature integrity dimension.setSignerInfo(String signerInfo) Sets additional signer information.setSigningKey(String signingKey) Sets the key identifier used for signing.setVerifyMaterialVersion(Integer verifyMaterialVersion) Sets the key-material version that performed the signature verification.setVerifyWarnings(List<CryptoWarning> verifyWarnings) Sets warnings related to the signature verification operation.toString()Returns string representation for debugging.
-
Constructor Details
-
DecryptVerifyResult
public DecryptVerifyResult()Default constructor initializing empty warning lists.
-
-
Method Details
-
getDecryptedData
public byte[] getDecryptedData()Returns the decrypted plaintext bytes.Security Warning: Always check
isSignatureValid()before trusting this data. Invalid signatures may indicate tampering.Note: Returns the internal array directly (no defensive copy). Callers who need to mutate or retain the result should copy it via
Arrays.copyOf(result.getDecryptedData(), ...). Contrast withDecryptResult.getDecryptedData(), which returns a copy.- Returns:
- decrypted plaintext bytes; may be
nullif operation failed
-
setDecryptedData
Sets the decrypted plaintext bytes.- Parameters:
decryptedData- the plaintext- Returns:
- this instance for fluent API
-
getDecryptKeyRequested
Gets the key identifier requested for decryption.- Returns:
- requested decrypt key ID
-
setDecryptKeyRequested
Sets the key identifier requested for decryption.- Parameters:
decryptKeyRequested- the key ID- Returns:
- this instance for fluent API
-
getDecryptMaterialVersion
Gets the key-material version (ank_kv) that performed the decryption under the requested Stable KID.- Returns:
- decrypt material version;
nullwhen not resolvable — never 0
-
setDecryptMaterialVersion
Sets the key-material version that performed the decryption.- Parameters:
decryptMaterialVersion- the material version- Returns:
- this instance for fluent API
-
getDecryptAlgorithmUsed
Gets the algorithm used for decryption.Example: "ML-KEM-1024+A256GCM", "RSA-OAEP-256+A256GCM"
- Returns:
- decryption algorithm
-
setDecryptAlgorithmUsed
Sets the algorithm used for decryption.- Parameters:
decryptAlgorithmUsed- the algorithm- Returns:
- this instance for fluent API
-
getDecryptWarnings
Gets structured warnings related to the decryption operation.Warnings are type-safe instances allowing pattern matching:
for (CryptoWarning warning : result.getDecryptWarnings()) { switch (warning) { case KeyExpirationWarning kew when kew.severity() == WarningSeverity.CRITICAL -> logger.error("URGENT: Decryption key expires in {} days", kew.daysRemaining()); case UsageLimitWarning ulw -> planKeyRotation(ulw); case GenericWarning gw -> logger.info("Decrypt warning: {}", gw.rawMessage()); } }- Returns:
- unmodifiable list of decrypt warnings (never null, may be empty)
-
setDecryptWarnings
Sets warnings related to the decryption operation.- Parameters:
decryptWarnings- the warnings- Returns:
- this instance for fluent API
-
isSignatureValid
public boolean isSignatureValid()Checks if the signature verification succeeded.Critical: Always check this before trusting the plaintext. Decryption can succeed even if signature is invalid.
- Returns:
- true if signature verification passed
-
setSignatureValid
Sets whether signature verification succeeded.- Parameters:
signatureValid- true if signature is valid- Returns:
- this instance for fluent API
-
getSigningKey
Gets the key identifier used for signing (from JWS header).- Returns:
- signing key ID
-
setSigningKey
Sets the key identifier used for signing.- Parameters:
signingKey- the key ID- Returns:
- this instance for fluent API
-
getVerifyMaterialVersion
Gets the key-material version (ank_kv) that performed the signature verification under the requested Stable KID.- Returns:
- verify material version;
nullwhen not resolvable — never 0
-
setVerifyMaterialVersion
Sets the key-material version that performed the signature verification.- Parameters:
verifyMaterialVersion- the material version- Returns:
- this instance for fluent API
-
getSignAlgorithmUsed
Gets the algorithm used for signing (from JWS header).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
-
getSignerInfo
Gets additional signer information (if present in JWS claims).May contain subject, issuer, or other identity claims.
- Returns:
- signer information
-
setSignerInfo
Sets additional signer information.- Parameters:
signerInfo- the information- Returns:
- this instance for fluent API
-
getVerifyWarnings
Gets structured warnings related to the signature verification operation.Warnings are type-safe instances allowing pattern matching:
for (CryptoWarning warning : result.getVerifyWarnings()) { switch (warning) { case KeyExpirationWarning kew -> logger.warn("Verification key expires in {} days: {}", kew.daysRemaining(), kew.recommendedAction()); case UsageLimitWarning ulw when ulw.severity() == WarningSeverity.CRITICAL -> alertSecurityTeam("Verification key usage critical"); case GenericWarning gw -> logger.info("Verify warning: {}", gw.rawMessage()); } }- Returns:
- unmodifiable list of verify warnings (never null, may be empty)
-
setVerifyWarnings
Sets warnings related to the signature verification operation.- Parameters:
verifyWarnings- the warnings- Returns:
- this instance for fluent API
-
getQualifiedTimestamp
Returns the embedded RFC 3161 qualified timestamp from the inner JWS, when present.Informational only — never affects
isSignatureValid(). Returnsnullwhen the inner JWS carried no qualified timestamp.- Returns:
- the qualified-timestamp view, or
nullwhen absent - Since:
- 3.0.0
-
setQualifiedTimestamp
Sets the embedded qualified timestamp from the inner JWS.- Parameters:
qualifiedTimestamp- the timestamp view (may benull)- Returns:
- this instance for fluent API
-
getGcmTagVerdict
Returns the outer AES-GCM tag integrity dimension of the streaming decrypt-verify result.Populated only on the
streamingpath, which frames a two-verdict trailing part. On the in-memorydecryptThenVerifypath this isnull: an overallvalidresult already implies BOTH the outer GCM tag AND the inner JWS signature passed (fail-closed both-must-pass gate).- Returns:
"VALID"/"INVALID", ornullwhen not surfaced
-
setGcmTagVerdict
Sets the outer AES-GCM tag integrity dimension.- Parameters:
gcmTagVerdict- the GCM tag verdict token (may benull)- Returns:
- this instance for fluent API
-
getSignatureVerdict
Returns the inner JWS signature integrity dimension of the streaming decrypt-verify result.Populated only on the
streamingpath. On the in-memorydecryptThenVerifypath this isnull— seegetGcmTagVerdict().- Returns:
"VALID"/"INVALID", ornullwhen not surfaced
-
setSignatureVerdict
Sets the inner JWS signature integrity dimension.- Parameters:
signatureVerdict- the signature verdict token (may benull)- Returns:
- this instance for fluent API
-
hasAnyWarnings
public boolean hasAnyWarnings()Checks if there are any warnings (decrypt or verify).- Returns:
- true if either decryption or verification produced warnings
-
hasDecryptWarnings
public boolean hasDecryptWarnings()Checks if decryption operation produced warnings.- Returns:
- true if decrypt warnings list is non-empty
-
hasVerifyWarnings
public boolean hasVerifyWarnings()Checks if verification operation produced warnings.- Returns:
- true if verify warnings list is non-empty
-
isCompleteSuccess
public boolean isCompleteSuccess()Checks if operation completed successfully with no issues.Success means: signature valid AND no warnings.
- Returns:
- true if signature is valid and no warnings exist
-
toString
Returns string representation for debugging.
-