> For the complete documentation index, see [llms.txt](https://docs.payon.com.kh/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.payon.com.kh/payons-library/how-to-encrypt-data-with-rsa.md).

# 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;
