Class ReencryptResult
Contains the new compact JWE token produced by server-side re-encryption from one key to another, along with comprehensive metadata for both the old decryption key and the new encryption key. The plaintext is never exposed to the client during this operation.
Use Cases
- Key rotation for encrypted data without client-side decryption
- Migrating encrypted data to stronger algorithms
- Compliance-driven periodic key rotation
- Transparent key migration for legacy encrypted files
JWE Token Structure
The getJweToken() returns a compact JWE (RFC 7516) containing
five Base64URL segments:
BASE64URL(ProtectedHeader).
BASE64URL(EncryptedKey).
BASE64URL(IV).
BASE64URL(Ciphertext).
BASE64URL(AuthenticationTag)
Migration Mode
The isMigrationMode() flag indicates whether the operation handled
legacy ciphertext without a kid in the header. This is useful for
auditing and tracking migration workflows.
Thread Safety
Instances are effectively immutable after construction. All setters are for internal SDK use during deserialization. Once returned from SDK methods, instances are safe to share across threads.
Example
// Re-encrypt from old key to new key
ReencryptResult result = sdk.reencrypt("new-ml-kem-key", oldJweToken);
System.out.println("Re-encryption complete");
System.out.println("Old key: " + result.getOldKeyRequested() +
" (" + result.getOldKeyAlgorithmUsed() + ")");
System.out.println("New key: " + result.getNewKeyRequested() +
" (" + result.getNewKeyAlgorithmUsed() + ")");
System.out.println("Material versions: " + result.getSourceMaterialVersion() +
" -> " + result.getTargetMaterialVersion());
if (result.isMigrationMode()) {
System.out.println("Migrated legacy ciphertext to managed format");
}
// New JWE token ready for storage
String newJwe = result.getJweToken();
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns the new compact JWE token after re-encryption.Returns the hybrid algorithm used for encryption.Returns the original key identifier requested for encryption.Returns the hybrid algorithm used for decryption.Returns the original key identifier requested for decryption.Returns the key-material version that decrypted the original payload under the source Stable KID.Returns the PRIMARY key-material version that encrypted the new payload under the target Stable KID.Returns non-fatal warnings encountered during the re-encryption operation.booleanIndicates whether the operation ran in migration mode.
-
Constructor Details
-
ReencryptResult
public ReencryptResult()
-
-
Method Details
-
getJweToken
Returns the new compact JWE token after re-encryption.The token contains the same plaintext as the original JWE but encrypted with the new key. It is self-contained and can be stored or transmitted independently.
- Returns:
- the compact JWE string (five Base64URL segments); never
null
-
getOldKeyRequested
Returns the original key identifier requested for decryption.- Returns:
- non-null old kid
-
getSourceMaterialVersion
Returns the key-material version that decrypted the original payload under the source Stable KID.- Returns:
- source material version;
nullwhen not resolvable — never 0
-
getOldKeyAlgorithmUsed
Returns the hybrid algorithm used for decryption.- Returns:
- non-null algorithm identifier
-
getNewKeyRequested
Returns the original key identifier requested for encryption.- Returns:
- non-null new kid
-
getTargetMaterialVersion
Returns the PRIMARY key-material version that encrypted the new payload under the target Stable KID.- Returns:
- target material version;
nullwhen not resolvable — never 0
-
getNewKeyAlgorithmUsed
Returns the hybrid algorithm used for encryption.- Returns:
- non-null algorithm identifier
-
getWarnings
Returns non-fatal warnings encountered during the re-encryption operation.Warnings are type-safe instances that may relate to either the old decryption key or the new encryption key. Use pattern matching for programmatic handling:
ReencryptResult result = sdk.reencrypt("new-key", oldJweToken); if (result.getWarnings() != null && !result.getWarnings().isEmpty()) { for (CryptoWarning warning : result.getWarnings()) { switch (warning) { case KeyExpirationWarning kew -> { logger.warn("Key expiring in {} days - Old: {}, New: {}", kew.daysRemaining(), result.getOldKeyRequested(), result.getNewKeyRequested()); if (kew.severity() == WarningSeverity.CRITICAL) { alertOps("Urgent key rotation needed"); } } case UsageLimitWarning ulw -> logger.warn("{} - {}", ulw.message(), ulw.recommendedAction()); case GenericWarning gw when gw.rawMessage().contains("MIGRATION_MODE") -> auditLog("Migrated legacy ciphertext to managed format"); case GenericWarning gw -> logger.info("Warning: {}", gw.rawMessage()); } } }Common warning types:
KeyExpirationWarning: Old or new key approaching expirationUsageLimitWarning: Usage limits approachingGenericWarning: Migration mode, legacy format notices
- Returns:
- unmodifiable list of warnings (null if no warnings, never empty if non-null)
-
isMigrationMode
public boolean isMigrationMode()Indicates whether the operation ran in migration mode.Returns
trueif the original ciphertext lacked akidin the JWE header and asourceKidOverridewas provided to locate the decryption key. This is typical for legacy encrypted files.- Returns:
trueif migration mode was used;falsefor normal managed re-encryption
-