Class EncryptResult
Value object returned by one of the following SDK operations:
AuthenticatedSdk.encrypt(String, byte[])AuthenticatedSdk.encryptFile(String, java.nio.file.Path, java.nio.file.Path)AuthenticatedSdk.encryptFileStream(String, java.nio.file.Path, java.nio.file.Path)
This class encapsulates the full JWE produced by the ANKASecure platform
when encrypting, in the serialization that carries every recipient. For a
single-recipient key it is the RFC 7516 §7.1 Compact JWE; for a
composite KEM key, whose result has one recipient per component, it is the
§7.2 General JSON JWE (a JSON object with a recipients array),
because Compact Serialization holds exactly one recipient. A Compact JWE is
represented as five Base64URL-encoded segments separated by dots:
- Protected Header: JSON object containing JWE metadata
- Encrypted Key: the Data Encryption Key (DEK) encrypted
- Initialization Vector (IV): random nonce for AEAD
- Ciphertext: the encrypted file payload
- Authentication Tag: ensures integrity and authenticity
Thread Safety
Instances are immutable and thread-safe. All fields are final and collections are unmodifiable. Instances can be safely shared across threads without synchronization.
Usage Example
EncryptResult result = sdk.encrypt("my-key", data);
// Access immutable data
String jwe = result.getJweToken();
Integer materialVersion = result.getMaterialVersion();
// Inspect the key-material version that performed the operation
if (materialVersion != null) {
System.out.println("Encrypted with material version " + materialVersion);
}
// Check warnings
if (result.getWarnings() != null) {
result.getWarnings().forEach(System.out::println);
}
Builder Pattern
Instances are created using the Builder pattern:
EncryptResult result = EncryptResult.builder()
.jweToken("eyJhbGc...")
.keyRequested("my-key")
.materialVersion(2)
.algorithmUsed("ML-KEM-768")
.addWarning("KEY_ROTATED")
.build();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for constructing immutable EncryptResult instances. -
Method Summary
Modifier and TypeMethodDescriptionstatic EncryptResult.Builderbuilder()Creates a new builder for constructing EncryptResult instances.Returns the catalogue algorithm of the key that performed this encryption (e.g.Returns the JWE emitted by the server: Compact for a single-recipient key, General JSON for a composite KEM key.Returns the key identifier originally supplied by the client.Returns the key-material version (ank_kv) that performed the operation under the requested Stable KID;nullwhen not resolvable (e.g. utility mode) — never 0.Returns structured warnings encountered during the encryption operation.
-
Method Details
-
getJweToken
Returns the JWE emitted by the server: Compact for a single-recipient key, General JSON for a composite KEM key.- Returns:
- non-null JWE string, Compact or General JSON
-
getKeyRequested
Returns the key identifier originally supplied by the client.- Returns:
- requested kid (may be null)
-
getMaterialVersion
Returns the key-material version (ank_kv) that performed the operation under the requested Stable KID;nullwhen not resolvable (e.g. utility mode) — never 0.- Returns:
- material version (may be null)
-
getAlgorithmUsed
Returns the catalogue algorithm of the key that performed this encryption (e.g.ML-KEM-768,RSA-3072, or a composite pairing such asX25519+ML-KEM-768).- Returns:
- algorithm identifier (may be null)
-
getWarnings
Returns structured warnings encountered during the encryption operation.Warnings are type-safe instances allowing pattern matching and programmatic handling:
for (CryptoWarning warning : result.getWarnings()) { switch (warning) { case KeyExpirationWarning kew when kew.daysRemaining() <= 7 -> System.err.println("CRITICAL: " + kew.message()); case UsageLimitWarning ulw -> logWarning(ulw.message(), ulw.recommendedAction()); case GenericWarning gw -> System.out.println(gw.rawMessage()); } }The returned list is unmodifiable. Attempts to modify it will throw
UnsupportedOperationException.- Returns:
- unmodifiable list of warnings (null if no warnings, never empty if non-null)
-
builder
Creates a new builder for constructing EncryptResult instances.- Returns:
- a new Builder instance
-