After the upgrade of 3x version, Cocos Creator no longer supports JS. Direct package of Crypto-JS will cause an error, and require function cannot be identified in TS. However, we need JS package to achieve AES encryption and decryption in our project

Method of use

import CryptoJS from "crypto-js.min.js"; Const aseKey = "12345678" // Key must be: 8/16/32 bit var message = "abcd"; / / https://forum.cocos.org/t/topic/106414 / var/encryption to encrypt = CryptoJS. AES. The encrypt (message, CryptoJS.enc.Utf8.parse(aseKey), { mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString(); console.log(encrypt); //nlW4ll0zjyXE7NvC/wO9rQ== // Var decrypt = cryptojs.aes. decrypt(encrypt, cryptojs.enc.utf8.parse (aseKey), {mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 }).toString(CryptoJS.enc.Utf8); console.log(decrypt); //abcdCopy the code