JSFiddle - React, Tailwind, and code Playground

by Mohit Agrawal

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/crypto-js/4.1.1/crypto-js.min.js"></script>

JavaScript

const aesKEY = '7x!A%D*G-JaNdRgUkXp2s5v8y/B?E(H+';
const iv = 'ABCDEFGHIJKLMNOP';
const requestBody = {
  "app_data": {
    "bulk_link_upload": {},
    "application": [{
      "appl_rec_date": "26/04/2024 10:27:00",
      "prm_amount": "6724.00",
      "pay_mode": "12",
      "appl_number": "LA00000001",
      "product_code": "BGM",
      "sum_assured": "1000000",
      "application": "00000001",
      "prm_pay_period": "8",
      "benifit_term": "16"
    }],
    "insured": {
      "insured_name": "MOHIT AGRWAL",
      "address_1": "Address line 01",
      "address_2": "Address line 02",
      "pin_code": "421204",
      "insured_age": "35",
      "date_of_birth": "20/06/1988",
      "payer_name": "MOHIT AGRWAL"
    },
    "agent": {
      "agent_code": "002651"
    },
    "other_info": {
      "flag": "1",
      "dept_type": "DM"
    }
  },
  "payment_data": {
    "payment_type": "INITIAL",
    "return_url": "https://leapuat.adityabirlasunlifeinsurance.com/uat/#/",
    "request_id": 1714124664000,
    "request_date": "26/04/2024 15:04:24",
    "lob_id": "ABSLI",
    "payment_source_id": "LEAP_Prod",
    "amount": 6724,
    "product_type": "APPLICATION",
    "product_id": "LA00000001",
    "customer_name": "ABSLI TEST3631",
    "customer_email": "[email protected]",
    "customer_phone": "9898989898",
    "customer_id": "",
    "udf1": "LEAP_Prod",
    "udf2": "",
    "udf3": "",
    "udf4": "",
    "udf5": "",
    "udf6": "",
    "udf7": "",
    "udf8": "",
    "udf9": "",
    "udf10": ""
  }
}

function encryptAES(plainText) {
  let resp = CryptoJS.AES.encrypt(plainText, aesKEY, {
    iv: iv,
    mode: CryptoJS.mode.CBC,
  });
  
  return resp.toString();
}

// Example usage:
const encryptedText = encryptAES(JSON.stringify(requestBody));
console.log(encryptedText);