crypto-js

作者: Smallbore | 来源:发表于2019-03-28 12:43 被阅读0次

    crypto-js, AES加密解密

    //加密方法
      aesEncrypt(word, key, iv) {
        var key = CryptoJS.enc.Utf8.parse(key);
        var iv = CryptoJS.enc.Utf8.parse(iv);
        let srcs = CryptoJS.enc.Utf8.parse(word);
        let encrypted = CryptoJS.AES.encrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
        return encrypted.ciphertext.toString().toUpperCase();
      },
      //解密方法
      aesDecrypt(word, key, iv) {
        var key = CryptoJS.enc.Utf8.parse(key);
        var iv = CryptoJS.enc.Utf8.parse(iv);
        let encryptedHexStr = CryptoJS.enc.Base64.parse(word);  // 十六进制,Base64改Hex
        let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr);
        let decrypt = CryptoJS.AES.decrypt(srcs, key, { iv: iv, mode: CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7 });
        let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8);
        return decryptedStr.toString();
      },
    
    

    相关文章

      网友评论

          本文标题:crypto-js

          本文链接:https://www.haomeiwen.com/subject/atlqbqtx.html