How to encrypt data with RSA

Init required library to you page

<!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

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

Last updated