import {
    TripleDES,
    enc,
    mode,
    pad
} from 'crypto-js';

const KEY = process.env.VUE_APP_DEV_KEY;
const key = enc.Utf8.parse(KEY);

//TripleDES加密
const encryptByDES = (message) => {
    let encrypted = TripleDES.encrypt(message, key, {
        mode: mode.ECB,
        padding: pad.Pkcs7
    });
    return encrypted.toString();
}

//TripleDES解密
const decryptByDES = (ciphertext) => {
    let decrypted = TripleDES.decrypt({
        ciphertext: enc.Base64.parse(ciphertext)
    }, key, {
        mode: mode.ECB,
    });
    const value = decrypted.toString(enc.Utf8);
    return value;
}

export {
    encryptByDES,
    decryptByDES
}
