# How to encrypt data with RSA

## Init required library to you page

```html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
      <script th:src="@{https://pg.payon.com.kh/PGV2/static/js/jquery-3.4.1.min.js}" charset="utf-8" type="text/javascript"></script>
      <script th:src="@{https://pg.payon.com.kh/PGV2/static/js/jsencrypt.min.js}" charset="utf-8" type="text/javascript"></script>
      <script th:src="@{https://pg.payon.com.kh/PGV2/static/js/crypto-js.min.js}" charset="utf-8" type="text/javascript"></script>
 <head> 
 
 </html>   
```

### Prepare your JavaScript

```javascript
   let encrypt = new JSEncrypt({
        default_key_size: 2048
    })
    
    //YOUR PUBLIC KEY 
    var publicKey = $('#pubKey').val();
    
    var data = "TO BE ENCRYPTED DATA"
    
    encrypt.setPublicKey(publicKey);
    
    var _encryptedData = encrypt.encrypt(data);
    
```

## &#x20;


---

# 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.payon.com.kh/payons-library/how-to-encrypt-data-with-rsa.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.
