# Encryption Library API Secification

4.1.1 Data&#x20;

{% tabs %}
{% tab title="PHP" %}

| Function                                | Explanation                                                                                                                                                                                                                   |
| --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| function createSession($termId, $txnId) | <p>Encrypted session creation between client and server</p><ol><li><p>Input Param</p><p>1.1 termId: Terminal ID given by PayOn</p><p>1.2 txnId: Merchant transaction identification number</p></li><li>Return: none</li></ol> |
| function PayOnEncrypt($data)            | <p>Data encryption</p><ol><li><p>Input Param</p><p>1.1 data: Data to be encrypted</p></li><li>Return: Encrypted data</li></ol>                                                                                                |
| function PayOnDecrypt($data)            | <p>Data decryption</p><ol><li><p>Input Param</p><p>1.1 data: Data to be decrypted</p></li><li>Return: Decrypted data</li></ol>                                                                                                |
| function PayOnGenerateMAC($data)        | <p>Generate MAC value for message verification</p><ol><li><p>Input Param</p><p>1.1 data: MAC Data for generation</p></li><li>return: MAC value for message verification.</li></ol>                                            |
| {% endtab %}                            |                                                                                                                                                                                                                               |

{% tab title="Java or .NET" %}

| Function                                   | Explanation                                                                                                                                                                                                                                                                             |
| ------------------------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| String getVersion()                        | <p>Library version lookup</p><ol><li>Input Param: none</li><li>Return: Library </li></ol>                                                                                                                                                                                               |
| void createSession(termId, txnId)          | <p>Encrypted session creation between client and server</p><ol><li><p>Input Param</p><p>1.1 termId: Terminal ID given by PayOn</p><p>1.2 txnId: Merchant transaction identification number</p></li><li>Return: none</li></ol>                                                           |
| String PayOnEncrypt(data, isHexString)     | <p>Data encryption</p><ol><li><p>Input Param</p><p>1.1 data: Data to be encrypted<br>1.2 isHexString: False if the data to be encrypted is a general string, true if it is a Hex String.</p></li><li>Return: Encrypted data</li></ol>                                                   |
| String PayOnDecrypt(data)                  | <p>Data decryption</p><ol><li><p>Input Param</p><p>1.1 data: Data to be decrypted</p></li><li>Return: Decrypted data</li></ol>                                                                                                                                                          |
| String PayOnGenerateMAC(data, isHexString) | <p>Generate MAC value for message verification</p><ol><li><p>Input Param</p><p>1.1 data: MAC Data for generation<br>1.2 isHexString: False if the data to be encrypted is general string, true if it is a Hex String.</p></li><li>return: MAC value for message verification.</li></ol> |
| {% endtab %}                               |                                                                                                                                                                                                                                                                                         |
| {% endtabs %}                              |                                                                                                                                                                                                                                                                                         |

4.1.2 Message Encryption Example

{% tabs %}
{% tab title="PHP" %}

```
$payOnCipher = new PayOnCipher();
$payOnCipher->createSession($termId, $txnId);
$encryptData = $payOnCipher->PayOnEncrypt($data);
```

{% endtab %}

{% tab title="Java or .NET" %}

```
PayOnCipher cp = new PayOnCipher();
cp.createSession(termId, txnId);
String encryptData = cp.PayOnEncrypt(data, false);
```

{% endtab %}
{% endtabs %}

4.1.3 Message Decryption Example

{% tabs %}
{% tab title="PHP" %}

```
$payOnCipher = new PayOnCipher();
$payOnCipher->createSession($termId, $txnId);
$decryptData = $payOnCipher->PayOnDecrypt($data);
```

{% endtab %}

{% tab title="Java or .NET" %}

```
PayOnCipher cp = new PayOnCipher();
cp.createSession(termId, txnId);
String decryptData = cp.PayOnDecrypt(data);
```

{% endtab %}
{% endtabs %}

4.1.3 Message Generate MAC Example

{% tabs %}
{% tab title="PHP" %}

```
$payOnCipher = new PayOnCipher();
$payOnCipher->createSession($termId, $txnId);
$mac = $payOnCipher->PayOnGenerateMAC($data);
```

{% endtab %}

{% tab title="Java or .NET" %}

```
cp = new PayOnCipher();
cp.createSession(termId, txnId);
String mac = cp.PayOnGenerateMAC(data);
```

{% endtab %}
{% endtabs %}


---

# 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://apis.payon.com.kh/message-cryptography/encryption-library-api-secification.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.
