# Encryption of card data

## Working with the JWE Encryption Standard

To ensure data confidentiality during transmission, the JWE (JSON Web Encryption) standard is used, which defines the format for encrypted JSON messages.

To encrypt the Card Number (PAN), the public payment key (`payment_public_key`) is used, which is provided during key generation (see "[Key Generation](https://docs.merchant.alb.ua/avtorizaciya-2.0/generaciya-klyuchiv#proces-otrimannya-klyuchiv)" documentation).

The key conforms to the JWK (JSON Web Key) format:

JSON

```json
"paymentPublicKey": 
{
    "kty": "EC",
    "x": "Hp833OY6a0VbFD1j8xFyXWcAA-HOlyr7B_-B05esZUy32RA41s0oGAMTal23AX9d",
    "y": "WGHeR9PhKRymoA-ggsR3VkQTgdfzt7PWa8P2qNpu0cV83lmLxE57b8rR7ajBurvj",
    "crv": "P-384"
}
```

> The Public Payment Key (`payment_public_key`) corresponds to the parameters:
>
> * "[kty](https://datatracker.ietf.org/doc/html/rfc7518#section-6.1)": "EC" - Key type (Elliptic Curve)
> * "[crv](https://datatracker.ietf.org/doc/html/rfc7518#section-6.2.1.1)": "P-384" - Elliptic Curve type
> * "[use](https://datatracker.ietf.org/doc/html/rfc7517#section-4.2)": "enc" – Parameter used for key encryption
> * "[alg](https://datatracker.ietf.org/doc/html/rfc7518#section-4.1)": ECDH-ES+A256KW - Algorithm for which the key is used

#### Example Endpoint for Encryption:

> Warning:
>
> The request is for testing purposes only. It is forbidden to execute the request with real keys. Encryption must be implemented on your side.

## Encrypting a Message using JWK

> Encrypts the transmitted message (e.g., card number, or card expiration date and CVV) using the public JWK key (EC).<br>

```json
{"openapi":"3.0.3","info":{"title":"Encrypt Card Data API","version":"1.0.0"},"servers":[{"url":"https://api-ecom-release.develop.bankalliance.ua"}],"paths":{"/cipher/encrypt_by_jwk":{"post":{"summary":"Encrypting a Message using JWK","description":"Encrypts the transmitted message (e.g., card number, or card expiration date and CVV) using the public JWK key (EC).\n","parameters":[{"name":"message","in":"query","description":"Message to encrypt (e.g., card number, or card expiration date and CVV)","required":true,"schema":{"type":"string"}}],"requestBody":{"required":true,"content":{"application/json":{"schema":{"type":"object","required":["kty","crv","x","y"],"properties":{"kty":{"type":"string","enum":["EC"],"description":"Key Type (EC)"},"crv":{"type":"string","description":"Curve Type"},"x":{"type":"string","description":"X-coordinate of the public key (base64url)"},"y":{"type":"string","description":"Y-coordinate of the public key (base64url)"}}}}}},"responses":{"200":{"description":"Successful encryption. Returns the encrypted message (e.g., JWE token).","content":{"text/plain":{"schema":{"type":"string"}}}},"400":{"description":"Bad Request (e.g., missing parameters)"},"500":{"description":"Internal Server Error"}},"tags":["Encryption"]}}}}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.merchant.alb.ua/en/authorization-2.0/encryption-of-card-data.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
