Invalid Key State
URI: https://docs.ankatech.co/errors/invalid-key-state
HTTP Status: 422 Unprocessable Entity
When you see this
The requested cryptographic operation cannot be performed because the key is in an invalid state for the operation. The key exists but its current lifecycle state prevents the requested usage.
Common Causes
-
Expired key
Attempting to use a key that has passed its expiration date for encryption or signing operations. -
Revoked key
Trying to perform operations with a key that has been explicitly revoked. -
Suspended key
The key has been temporarily suspended and cannot be used until reactivated. -
Pre-activation key
Attempting to use a key before its activation date has been reached. -
Destroyed key material
The key metadata exists but the cryptographic material has been destroyed. -
Usage limit exceeded
The key has reached its maximum usage count and cannot perform more operations. -
Wrong operation for key state
Attempting operations not allowed in the current state (e.g., trying to encrypt with a decrypt-only key in post-rotation state).
How to Resolve
- Check key status
- Query the key details endpoint to verify the current state.
-
Review the key's lifecycle status:
ACTIVE,SUSPENDED,EXPIRED,REVOKED,DESTROYED. -
For expired keys
- Generate a new key to replace the expired one.
- Use key rotation APIs to migrate from the expired key.
-
Decryption may still be allowed for data recovery.
-
For revoked keys
- Revocation is permanent; generate a new key.
-
Historical decryption/verification may be permitted based on policy.
-
For suspended keys
- Contact an administrator to reactivate the key.
-
Investigate why the key was suspended (security incident, audit requirement).
-
For usage-limited keys
- Check the current usage count against the limit.
- Request a limit increase or generate a new key.
-
Implement key rotation before reaching limits.
-
For pre-activation keys
- Wait until the activation date.
- Verify the activation timestamp is correctly set.
Response Example
{
"error": {
"code": "INVALID_KEY_STATE",
"message": "Key cannot be used for the requested operation",
"detail": "Key 'mykey-2024' is in EXPIRED state. Encryption operations are not allowed.",
"timestamp": "2025-01-15T10:30:00Z",
"traceId": "550e8400-e29b-41d4-a716-446655440000",
"type": "https://docs.ankatech.co/errors/invalid-key-state"
},
"key_info": {
"kid": "mykey-2024",
"state": "EXPIRED",
"expired_at": "2024-12-31T23:59:59Z",
"allowed_operations": ["DECRYPT", "VERIFY"],
"denied_operations": ["ENCRYPT", "SIGN"]
}
}
Key Lifecycle States
| State | Allowed Operations | Description |
|---|---|---|
| PRE_ACTIVE | None | Key created but not yet activated |
| ACTIVE | All permitted operations | Normal operational state |
| SUSPENDED | None (configurable) | Temporarily disabled |
| EXPIRED | Decrypt/Verify only | Past expiration date |
| REVOKED | Decrypt/Verify (configurable) | Permanently disabled |
| DESTROYED | None | Key material destroyed |
For more information about key lifecycle management, see the Key Management API documentation.