Package co.ankatech.ankasecure.sdk.model
Class EncryptResult
java.lang.Object
co.ankatech.ankasecure.sdk.model.EncryptResult
Immutable result returned by encryption operations.
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 Compact JWE produced by the Anka Secure platform when encrypting a file. 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 algorithm negotiated by the server for this encryption operation (e.g.Returns the raw Compact JWE exactly as emitted by the server.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 raw Compact JWE exactly as emitted by the server.- Returns:
- non-null Compact JWE string
-
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 algorithm negotiated by the server for this encryption operation (e.g.ML-KEM-768+A256GCM,AES-256-GCM,RSA-OAEP-SHA256).- 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
-