var pako = require("pako");

function O(t) {
    var e, n, a = t.words.length, i = new Uint8Array(t.sigBytes), r = 0;
    for (n = 0; n < a; n++)
        e = t.words[n],
            i[r++] = e >> 24,
            i[r++] = e >> 16 & 255,
            i[r++] = e >> 8 & 255,
            i[r++] = 255 & e;
    return i
}

const CryptoJS = require("crypto-js");

let secret_value = 'cmmgfgehahweuuii'; //密匙 16位
// let iv_value = '4rshXwWcMQf2xdxF'; // 初始向量 initial vector 16位

// 密匙和向量处理
let secret = CryptoJS.enc.Utf8.parse(secret_value);
// let iv = CryptoJS.enc.Utf8.parse(iv_value);

// 将加密结果转换为字符串
encrypted = '[encoded data, 41856 characters]';


// 解密，传入密文，密钥盒向量设置加密与填充模式
let decrypted = CryptoJS.AES.decrypt(encrypted, secret, {
    // iv: iv,
    // mode 支持 CBC, CFB,CTB,ECB,OFB,OFB, 默认CBC
    mode: CryptoJS.mode.ECB,

    // NoPadding, zeropadding 默认Pkcs7 即 pkcs5
    padding: CryptoJS.pad.Pkcs7
});

console.log(decrypted);
i = O(decrypted);
console.log(i);
r = pako.ungzip(i, {
    to: "string"
});

console.log(r);
// 将解密结果转换为utf8字符串
// decrypted = CryptoJS.enc.Utf8.stringify(decrypted);
// console.log(decrypted);
// console.log(encrypted);
