Class KeyMetadata
This class provides a complete view of a key's identity, configuration, lifecycle,
and usage statistics. It is returned by the read-only key query operations
(listKeys / getKeyMetadata).
Key Type Detection:
- Simple key:
ktyis "ML-KEM", "ML-DSA", "RSA", "EC", "oct", etc. - Composite KEM:
ktyis "COMPOSITE_KEM_COMBINE" - Composite Signature:
ktyis "COMPOSITE_SIGNATURE"
Usage Examples
Check Key Type
KeyMetadata metadata = sdk.getKeyMetadata(kid);
if (metadata.isComposite()) {
System.out.println("Composite key: " + metadata.getKty());
if (metadata.isCompositeKem()) {
System.out.println("KDF used: " + metadata.getKdf());
}
} else {
System.out.println("Simple key: " + metadata.getKty());
}
Check Lifecycle Status
System.out.println("Status: " + metadata.getStatus());
System.out.println("Created: " + metadata.getCreatedAt());
System.out.println("Expires: " + metadata.getExpiresAt());
System.out.println("Usage: " + metadata.getUsageCount() + " / " + metadata.getMaxUsageLimit());
Lifecycle States
The getStatus() field indicates the current lifecycle state:
- ACTIVE: Key is operational and can be used for cryptographic operations
- ROTATED: Key material superseded by a newer version under the same kid
- EXPIRED: Key past
getExpiresAt()timestamp, cannot be used - REVOKED: Key manually revoked, permanently disabled
- DISABLED: Key temporarily disabled by administrator
- USAGE_EXCEEDED: Key reached
getMaxUsageLimit(), cannot be used
Thread Safety
Instances are immutable value objects safe to share across threads.
- Since:
- 3.0.0
- See Also:
-
AuthenticatedSdk.getKeyMetadata(String)co.ankatech.ankasecure.sdk.AuthenticatedSdk#listKeys()
-
Constructor Summary
ConstructorsConstructorDescriptionKeyMetadata(String kid, String kty, String alg, String kdf, List<String> keyOps, Boolean exportable, KeyOrigin origin, Boolean restricted, String status, ZonedDateTime createdAt, ZonedDateTime expiresAt, ZonedDateTime softLimitExpiration, Integer usageCount, Integer softUsageLimit, Integer maxUsageLimit) Constructor for internal SDK use. -
Method Summary
Modifier and TypeMethodDescriptiongetAlg()Returns the algorithm identifier.Returns the key creation timestamp.Returns the hard expiration timestamp.Returns whether the key can be exported.getKdf()Returns the key derivation function for composite KEM keys.Returns the permitted key operations.getKid()Returns the unique key identifier.getKty()Returns the key type.Returns the hard usage limit.Returns the key origin.Returns whether the key is restricted (legacy format).Returns the soft expiration (warning threshold) timestamp.Returns the soft usage limit (warning threshold).Returns the current lifecycle status.Returns the current usage counter.booleanChecks if this is a composite key.booleanChecks if this is a composite KEM key.booleanChecks if this is a composite signature key.
-
Constructor Details
-
KeyMetadata
public KeyMetadata(String kid, String kty, String alg, String kdf, List<String> keyOps, Boolean exportable, KeyOrigin origin, Boolean restricted, String status, ZonedDateTime createdAt, ZonedDateTime expiresAt, ZonedDateTime softLimitExpiration, Integer usageCount, Integer softUsageLimit, Integer maxUsageLimit) Constructor for internal SDK use. Use mapper in KeyManagementServiceImpl.
-
-
Method Details
-
getKid
Returns the unique key identifier.- Returns:
- key identifier (never
null)
-
getKty
Returns the key type.Examples: "ML-KEM", "ML-DSA", "RSA", "EC", "oct", "COMPOSITE_KEM_COMBINE", "COMPOSITE_SIGNATURE"
- Returns:
- key type (never
null)
-
getAlg
Returns the algorithm identifier.For simple keys: Single algorithm (e.g., "ML-KEM-768", "RSA-4096")
For composite keys: Combined algorithms (e.g., "X25519+ML-KEM-768", "Ed25519+ML-DSA-44")- Returns:
- algorithm identifier (never
null)
-
getKdf
Returns the key derivation function for composite KEM keys.Only present for
kty="COMPOSITE_KEM_COMBINE". Common values: "HKDF-SHA256", "HKDF-SHA512"- Returns:
- KDF identifier, or
nullif not a composite KEM key
-
getKeyOps
Returns the permitted key operations.Common values: "encrypt", "decrypt", "sign", "verify", "wrapKey", "unwrapKey"
- Returns:
- unmodifiable list of operations (never
null, may be empty)
-
getExportable
Returns whether the key can be exported.- Returns:
trueif exportable,falseotherwise, ornullif unspecified
-
getOrigin
Returns the key origin.- Returns:
- key origin (GENERATED, IMPORTED, DERIVED), or
nullif unspecified
-
getRestricted
Returns whether the key is restricted (legacy format).- Returns:
trueif restricted,falseotherwise, ornullif unspecified
-
getStatus
Returns the current lifecycle status.Common values: "active", "rotated", "expired", "revoked", "disabled", "usage_exceeded"
- Returns:
- status string (never
null)
-
getCreatedAt
Returns the key creation timestamp.- Returns:
- creation timestamp (never
null)
-
getExpiresAt
Returns the hard expiration timestamp.- Returns:
- expiration timestamp, or
nullif no expiration set
-
getSoftLimitExpiration
Returns the soft expiration (warning threshold) timestamp.- Returns:
- soft limit timestamp, or
nullif no soft limit set
-
getUsageCount
Returns the current usage counter.- Returns:
- usage count (never
null, defaults to 0)
-
getSoftUsageLimit
Returns the soft usage limit (warning threshold).- Returns:
- soft usage limit, or
nullif no soft limit set
-
getMaxUsageLimit
Returns the hard usage limit.- Returns:
- maximum usage limit, or
nullif no limit set
-
isComposite
public boolean isComposite()Checks if this is a composite key.- Returns:
trueif kty starts with "COMPOSITE_"
-
isCompositeKem
public boolean isCompositeKem()Checks if this is a composite KEM key.- Returns:
trueif kty is "COMPOSITE_KEM_COMBINE"
-
isCompositeSignature
public boolean isCompositeSignature()Checks if this is a composite signature key.- Returns:
trueif kty is "COMPOSITE_SIGNATURE"
-