先下载CryptoJS并引入
1、Hex格式:
const key = CryptoJS.enc.Utf8.parse("cmp_security_key");
    const options = {
      mode: CryptoJS.mode.ECB,
      padding: CryptoJS.pad.Pkcs7
   }
加密
 const encryptedStr = CryptoJS.AES.encrypt("222", key, options).ciphertext.toString();
console.log(encryptedStr);
解密
 const testdec = CryptoJS.AES.decrypt(CryptoJS.enc.Base64.stringify(CryptoJS.enc.Hex.parse(encryptedStr)), key, options).toString(CryptoJS.enc.Utf8);
 console.log(testdec);

2、Base64

加密

    const encryptedStr1 = CryptoJS.AES.encrypt("222", key, options).toString();

   console.log(encryptedStr1);

解密

    const testdec1 = CryptoJS.AES.decrypt(encryptedStr1, key, options).toString(CryptoJS.enc.Utf8);
    console.log(testdec1);

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-24
  • 2021-12-05
  • 2021-11-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-05
  • 2022-12-23
相关资源
相似解决方案