前端Crypto.JS加密解密


先下載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);

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM