> ## Documentation Index
> Fetch the complete documentation index at: https://docs.basaltic.sh/llms.txt
> Use this file to discover all available pages before exploring further.

# Rewrap ciphertext with current key material

> Rewrap ciphertext or a wrapped data key under the current version of the same enabled encrypt_decrypt key. No plaintext is returned. For an AAD envelope only the wrapped data key changes; the payload, authentication tag, and original AAD requirement are preserved. Rotation itself does not rewrite stored ciphertext; replace the stored value with this result when migration is desired.

<Info>
  Requires the IAM action **`kms:Rewrap`**. See [KMS permissions](/kms/permissions) for the full list, what each one covers, and an example policy.
</Info>


## OpenAPI

````yaml /api-reference/specs/kms.yaml post /v1/keys/{key_id}/rewrap
openapi: 3.0.3
info:
  title: Basaltic KMS API
  version: 1.0.0
  description: |
    Customer-managed encryption keys. Encrypt and decrypt directly, or let
    another service — secrets, storage, images — wrap its data keys with one
    of yours.
  contact:
    name: Basaltic Support
    email: ping@basaltic.sh
  license:
    name: Proprietary
    url: https://basaltic.sh/terms
servers:
  - url: https://kms.{region}.basaltic.sh
    description: Regional API endpoint
    variables:
      region:
        default: sa-saopaulo-1
        description: Region code
security:
  - BearerAuth: []
paths:
  /v1/keys/{key_id}/rewrap:
    parameters:
      - name: key_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
    post:
      tags:
        - KMS
      summary: Rewrap ciphertext with current key material
      description: >-
        Rewrap ciphertext or a wrapped data key under the current version of the
        same enabled encrypt_decrypt key. No plaintext is returned. For an AAD
        envelope only the wrapped data key changes; the payload, authentication
        tag, and original AAD requirement are preserved. Rotation itself does
        not rewrite stored ciphertext; replace the stored value with this result
        when migration is desired.
      operationId: rewrap
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RewrapRequest'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EncryptResponse'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          description: Key or rotation not found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '409':
          description: Key state, usage, or active rotation prevents this operation
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '500':
          $ref: '#/components/responses/InternalServerError'
      security:
        - BearerAuth: []
components:
  schemas:
    RewrapRequest:
      type: object
      required:
        - ciphertext
      properties:
        ciphertext:
          type: string
          format: byte
          description: >-
            Base64-encoded ciphertext or wrapped data key produced by this KMS
            key. AAD is neither required nor changed.
    EncryptResponse:
      type: object
      properties:
        ciphertext:
          type: string
          format: byte
          example: AQIDBHByb2QtbWFzdGVyL2VuY3J5cHRlZA==
          description: |
            Base64-encoded opaque, versioned ciphertext. Store verbatim;
            do not parse its internal layout. Decrypt selects the original
            material version automatically after rotation.
        key_crn:
          type: string
          example: crn:kms:sa-saopaulo-1:my-account:key/prod-master
          description: CRN of the key the ciphertext was sealed under.
    Error:
      type: object
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
            - request_id
          properties:
            code:
              type: string
              description: Error code identifying the type of error
              example: INVALID_INPUT
            message:
              type: string
              description: Human-readable error message
              example: Invalid request parameters
            params:
              type: object
              additionalProperties: true
              description: >-
                Optional non-sensitive values for interpolation of localized
                errors, keyed by error code. Never present for server errors.
              example:
                instances: 2
                pools: 0
            request_id:
              type: string
              format: uuid
              description: Request ID for debugging
              example: 550e8400-e29b-41d4-a716-446655440000
  responses:
    BadRequest:
      description: Invalid request parameters
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: INVALID_INPUT
              message: Invalid request parameters
              request_id: 550e8400-e29b-41d4-a716-446655440000
    Unauthorized:
      description: Authentication required or token invalid
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: UNAUTHORIZED
              message: Authentication required
              request_id: 550e8400-e29b-41d4-a716-446655440000
    Forbidden:
      description: Insufficient permissions
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: ACCESS_DENIED
              message: You don't have permission to perform this action
              request_id: 550e8400-e29b-41d4-a716-446655440000
    InternalServerError:
      description: Internal server error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
          example:
            error:
              code: INTERNAL_ERROR
              message: An internal error occurred
              request_id: 550e8400-e29b-41d4-a716-446655440000
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: |
        An OAuth 2.0 bearer token, sent as `Authorization: Bearer <token>`.
        This is the recommended way to authenticate.

        Get one by exchanging a service account's access key pair at
        `POST /v1/oauth/token` with `grant_type=client_credentials`. It is the
        standard client-credentials grant, so any OAuth-aware library will
        obtain and refresh it for you.

        ```
        curl -s -u "$KEY_ID:$SECRET" -d grant_type=client_credentials \
          https://iam.basaltic.sh/v1/oauth/token
        ```

        Tokens last an hour by default. The same access key pair is separately
        your AWS SigV4 credential for the S3-compatible object endpoint, which
        speaks nothing else.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.