# Encryption

All server to server data should be encrypted using AES-256-CBC with HMAC. Pseudo Code for encryption is explained below:

```
Input: plain_text Input: api_secret iv=generated random 16 byte enc_text=Encrypt plain_text Using AES-256-CBC,
api_secret & iv b_iv=Base64 Encode iv concat_string=b_iv + enc_text [Concat string] mac=Generate SHA256 Hash of concat_string using api_secret [HMAC] data_array=array of iv,
enc_text,
mac json_string=Convert data_array into Json String final_encrypted_text=Base64 Encode json_string
```

### **PHP Example**

```php
function encrypt($text, $key) {
    $iv = random_bytes(16);
    $value = openssl_encrypt(serialize($text), 'AES-256-CBC', $key, 0, $iv);
    $bIv = base64_encode($iv);
    $mac = hash_hmac('sha256', $bIv.$value, $key);
    $c_arr = ['iv' => $bIv, 'value' => $value, 'mac' => $mac];
    $json = json_encode($c_arr);
    $crypted = base64_encode($json);
    return $crypted;
}
```

{% hint style="info" %}
Encryption should be done using the API Secret Key.
{% endhint %}

{% hint style="danger" %}
**Note:** Do not transfer or send this API Secret Key in any request. Do not share API Secret Key with anyone for security reasons.
{% endhint %}


---

# 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.paykun.com/technical-guide/web-integration/checkout-integration/web-integration-encryption.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.
