Skip to content

Re-encrypt or re-sign under a new key

Move protected data to another key without handling the plaintext yourself: re-encrypt a JWE for a new key, or replace a signature with one made by a new key, for example to move from a classical to a post-quantum or hybrid key.

Who can do it

An application authenticated as a cryptographic actor of your tenant. Its token must carry the scope of the operation, and the actor must hold an active Capability Grant covering the source and the target key:

Operation Scope Capability Grant
Re-encrypt in one request secure.reencrypt REENCRYPT on the source and target keys
Re-encrypt a stream stream.reencryptStream REENCRYPT on the source and target keys
Re-sign in one request secure.resign RESIGN on the source and target keys, and VERIFY on every signer that is kept
Re-sign a stream stream.resignStream RESIGN on the source and target keys, and VERIFY on every signer that is kept

No console role performs these operations.

Before you start

Steps

  1. Re-encrypt:
    • Java SDK: sdk.reencrypt(newKid, jwe) returns a ReencryptResult; keep getJweToken(). For files, sdk.reencryptFile(newKid, input, output) picks the path from the input's format; reencryptFileStream(newKid, sourceKid, input, output) always streams.
    • Crypto CLI: AnkaSecureCLI reencrypt-file --new-kid <kid> --input-file <file> --output-file <file>, or reencrypt-file-stream with the same options.
    • API: POST /api/v3/crypto/reencrypt with {"jweToken": {...}, "newKid": "<kid>"}. For a stream, POST /api/v3/crypto/stream/reencrypt with newKid as a query parameter.
  2. Re-sign:
    • Java SDK: sdk.resign(newKid, jws) returns a ResignResult; keep getJwsToken(). For a detached signature, resignFileStream(oldJwsHeader, newKid, input, output).
    • Crypto CLI: AnkaSecureCLI resign-file --new-kid <kid> --old-signature-file <file> --new-signature-file <file>, or AnkaSecureCLI resign-file-stream --new-kid <kid> --old-signature-file <file> --input-file <file> --new-signature-file <file> for a detached signature.
    • API: POST /api/v3/crypto/resign with {"jwsToken": {...}, "newKid": "<kid>"}. For a stream, POST /api/v3/crypto/stream/resign.
  3. Name the source key when the token does not name exactly one: sourceKid in the request, --source-kid in the CLI or the sourceKid argument of the SDK methods. For a JWE addressed to several keys, or a JWS signed by several keys, sourceKid is required and names the one recipient or signer that is replaced; every other one is kept in its position.
  4. On a streaming re-encryption, wait for the verdict part. The source's integrity is known only at the end of the stream; an INVALID verdict means the new ciphertext must not be used. The SDK and the CLI keep the output only on a VALID verdict.

What you see when it worked

A re-encryption returns a new JWE under a fresh content encryption key for the target key, with the source and target keys, their material versions and algorithms. When a JWE addressed to several keys is re-encrypted, the replaced key can no longer read the result, and the kept recipients are listed.

A re-signature returns the JWS with the new signature in place of the old one, over the same payload. Every existing signature is verified first; a re-signature never replaces a signature that does not verify.

If it fails

What you see Cause What to do
400 naming sourceKid or newKid sourceKid is missing where required, names no recipient or signer of the token, or newKid names one that is kept Name the one key to replace, and a target that is not already in the token
400 .../errors/invalid-input on a re-signature A signature in the token does not verify. Nothing is signed Do not trust the token
400 .../errors/key-operation-incompatible The source and target keys are of different classes, for example a symmetric source and an asymmetric target Choose a target of the same class
403 .../errors/forbidden The token lacks the scope, or the actor holds no grant covering the source and target keys Ask a tenant administrator to check the actor's grants
404 .../errors/not-found The source or target key does not exist or cannot serve the operation Check the key identifiers
409 .../errors/invalid-key-state or .../errors/conflict A key is revoked or suspended Use active keys
422 with the detail "Unable to decrypt: key mismatch or ciphertext integrity failure." The source JWE was altered, or its key confirmation does not match Do not use the data
Streaming re-encryption ends with verdict INVALID The source ciphertext was altered Discard the output; the SDK raises StreamIntegrityException and writes no file

Without the console

These operations have no console screen.

Surface How
Java SDK reencrypt, reencryptFile, reencryptFileStream, resign, resignFileCompact, resignFileStream on AuthenticatedSdk
Crypto CLI AnkaSecureCLI reencrypt-file, reencrypt-file-stream, resign-file, resign-file-stream
API POST /api/v3/crypto/reencrypt (reencryptData), POST /api/v3/crypto/stream/reencrypt (reencryptDataStream), POST /api/v3/crypto/resign (resignData), POST /api/v3/crypto/stream/resign (resignDataStream)