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

# Get the encryption public key

> Returns the RSA public key used to encrypt card data before it is sent to
lite, for the merchant (the `x-business-account-id` account when sent,
otherwise the API key's).

Encrypt the card details into a JWE with this key and send the result as
`data` when creating an instrument. The raw card number then never reaches
lite in plain text.

The key is created on the first call and returned unchanged on later calls,
so it can be cached. While lite is still creating it, the response is `{}`
without `public_key_pem`: call again after a few seconds. This is the same
key as `POST /cryptography/liteEncrypted/session`.



## OpenAPI

````yaml /openapi/payment-instruments.json get /cryptography/key
openapi: 3.1.0
info:
  title: lite - Payment Instruments
  version: 1.0.0
servers:
  - url: https://api.lite.sa
    description: Production
security:
  - ApiKeyAuth: []
tags:
  - name: Payment Instruments
    description: Create, manage, and perform actions on payment instruments
  - name: Encryption
    description: Get the public key used to encrypt card data before sending it to lite
paths:
  /cryptography/key:
    get:
      tags:
        - Encryption
      summary: Get the encryption public key
      description: >-
        Returns the RSA public key used to encrypt card data before it is sent
        to

        lite, for the merchant (the `x-business-account-id` account when sent,

        otherwise the API key's).


        Encrypt the card details into a JWE with this key and send the result as

        `data` when creating an instrument. The raw card number then never
        reaches

        lite in plain text.


        The key is created on the first call and returned unchanged on later
        calls,

        so it can be cached. While lite is still creating it, the response is
        `{}`

        without `public_key_pem`: call again after a few seconds. This is the
        same

        key as `POST /cryptography/liteEncrypted/session`.
      operationId: lite.cryptography.getPublicKey
      parameters:
        - $ref: '#/components/parameters/x-correlation-id'
        - $ref: '#/components/parameters/x-business-account-id'
      responses:
        '201':
          $ref: '#/components/responses/PublicKey'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  parameters:
    x-correlation-id:
      name: x-correlation-id
      in: header
      required: false
      description: >-
        Unique identifier for request tracing. Generated by the client or server
        if not provided.
      schema:
        type: string
        format: uuid
        example: 550e8400-e29b-41d4-a716-446655440000
    x-business-account-id:
      name: x-business-account-id
      in: header
      required: false
      description: >-
        The business account to act on, for platform use cases. When sent, that
        account is the merchant for the request: resources are created under it,
        reads and `404` checks are scoped to it, and per-merchant uniqueness
        (such as `merchant_reference_id`) applies within it. The API key's own
        account is recorded as the account acting on its behalf. Omit it to act
        on the API key's own account.
      schema:
        type: string
        format: uuid
        example: 550e8400-e29b-41d4-a716-446655440000
  responses:
    PublicKey:
      description: Public key returned.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/PublicKeyResponse'
    Unauthorized:
      description: >
        lite's API gateway couldn't authenticate the request: the API key is
        missing, malformed,

        unknown or revoked, or the request sent an `Authorization` header. The
        body is the gateway's,

        not the `errors` array.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/GatewayUnauthorized'
    Forbidden:
      description: >
        The request was refused.


        Returned when:

        - The API key lacks the permission for this operation (`FORBIDDEN`, in
        the `errors` array)

        - `x-business-account-id` names an account the key can't act on

        - The gateway's security filter matched markup or code-like text in the
        body, query or headers
          (gateway body, with an `X-Security-Block` header)
      content:
        application/json:
          schema:
            oneOf:
              - $ref: '#/components/schemas/ApiErrorResponse'
              - $ref: '#/components/schemas/GatewayError'
    InternalServerError:
      description: >
        An unexpected error occurred on the server.


        The request may have taken effect. Before you retry a create, check
        whether it went through:

        - For a payment, call `GET /payments?order_id=<reference>`.

        - A checkout session that was created answers a retry for the same
        `order.reference` with `409`.

        - Payments and payment links return this same error for 120 seconds to a
        retry with the same
          `x-idempotency-key`.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiErrorResponse'
  schemas:
    PublicKeyResponse:
      type: object
      description: >-
        The account's public key. On the account's first call, lite creates the
        key; if it isn't ready within a few seconds, the response is an empty
        object `{}` with the same status. Call again after a few seconds until
        `public_key_pem` is present.
      properties:
        public_key_pem:
          type: string
          description: >-
            RSA public key in PEM (SPKI) format. Use it to encrypt card data
            into a

            JWE with `alg` `RSA-OAEP-256` and `enc` `A256GCM`. Absent while lite
            is

            still creating the key.
          example: |-
            -----BEGIN PUBLIC KEY-----
            MIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEA...
            -----END PUBLIC KEY-----
    GatewayUnauthorized:
      type: object
      description: >-
        Body of a 401 from lite's API gateway. It is not the `errors` array that
        lite's services return. `reason` says what to fix.
      required:
        - error
        - reason
        - message
      properties:
        error:
          type: string
          example: unauthorized
        reason:
          type: string
          description: What to fix.
          example: MALFORMED_CREDENTIAL
          oneOf:
            - title: No Credentials
              const: NO_CREDENTIALS
              description: No `x-api-key` header
            - title: Malformed Credential
              const: MALFORMED_CREDENTIAL
              description: The key doesn't start with `sk_live_` or `sk_sandbox_`
            - title: API Key Invalid
              const: API_KEY_INVALID
              description: Unknown or revoked key
            - title: Auth Type Not Allowed
              const: AUTH_TYPE_NOT_ALLOWED
              description: 'The request sent `Authorization: Bearer` instead of `x-api-key`'
            - title: Both Credentials
              const: BOTH_CREDENTIALS
              description: 'The request sent both `x-api-key` and `Authorization: Bearer`'
        message:
          type: string
          example: Authentication failed - invalid or missing credentials
        correlationId:
          type: string
          description: >-
            Quote it to lite support. Also sent in the `X-Correlation-Id`
            response header. Spelled in camelCase, as the gateway sends it.
    ApiErrorResponse:
      type: object
      description: >
        Error body returned by endpoints behind the external exception filter.
        Branch on

        `errors[].code`; `message` is readable text whose wording may change.
      required:
        - errors
        - request_id
      properties:
        errors:
          type: array
          description: >-
            One item per problem. A validation failure returns one item per
            invalid field.
          minItems: 1
          items:
            type: object
            required:
              - category
              - code
              - message
              - retriable
            properties:
              category:
                type: string
                description: Broad class of the error
                enum:
                  - SETUP
                  - VALIDATION
                  - INSTRUMENT
                  - ISSUER
                  - FRAUD
                  - WORKFLOW
                  - CONNECTION
                  - SYSTEM
              code:
                type: string
                description: Stable error code to branch on
              message:
                type: string
                description: Human-readable description of the error
              field:
                type: string
                description: The invalid request field. Present on validation errors only.
              retriable:
                type: boolean
                description: >-
                  Whether a later retry of the same request may succeed. On
                  `POST /payments` and `POST /payment-links`, a retry with the
                  same `x-idempotency-key` (or, without one, the same reference)
                  within 120 seconds gets this same error back. So when
                  `retriable` is `true`, retry with a new key or wait 120
                  seconds.
        request_id:
          type: string
          description: Correlation ID of the request. Include it when contacting support.
    GatewayError:
      type: object
      description: >-
        Body of an error raised by lite's API gateway before the request reaches
        a service: an unknown path (404), a request blocked by the security
        filter (403, with an `X-Security-Block` header) or a body over 50 KB
        (413).
      required:
        - error
      properties:
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: integer
              example: 403
            message:
              type: string
              example: Forbidden
            details:
              type: string
              description: What the security filter matched. Absent on 404.
            timestamp:
              type: string
              format: date-time
            correlationId:
              type: string
              description: >-
                Quote it to lite support. Spelled in camelCase, as the gateway
                sends it, unlike the `correlation_id` in service errors.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: >-
        Your secret API key from the dashboard. Keys starting `sk_sandbox_` work
        in test mode and keys starting `sk_live_` in live mode, on the same base
        URL. Don't send an `Authorization` header with it.

````

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