/*
 * @Author: chenkangxu
 * @Date: 2022-04-18 20:15:11
 * @LastEditTime: 2022-04-18 20:15:11
 * @LastEditors: chenkangxu
 * @Description: 
 * @Github: 
 */
/*
 * @Author: chenkangxu
 * @Date: 2022-04-18 19:02:38
 * @LastEditTime: 2022-04-18 19:04:22
 * @LastEditors: chenkangxu
 * @Description: 
 * @Github: 
 */

// 第一种加密方式
import CryptoJS from 'crypto-js'
export default class Helper {
    // 加密
    static encryptByDES(ciphertext, key) {
        let keyHex = CryptoJS.enc.Utf8.parse(key);
        let ivHex = CryptoJS.enc.Utf8.parse(key);
        let encrypted = CryptoJS.DES.encrypt(ciphertext, keyHex, {
            iv: ivHex,
            mode: CryptoJS.mode.ECB,
            padding: CryptoJS.pad.Pkcs7
        });
        return encrypted.ciphertext.toString().toLowerCase();
    }
    // 解密
    static decryptByDES(ciphertext, key) {
        let keyHex = CryptoJS.enc.Utf8.parse(key);
        let ivHex = CryptoJS.enc.Utf8.parse(key);
        let decrypted = CryptoJS.DES.decrypt({
            ciphertext: CryptoJS.enc.Hex.parse(ciphertext)
        },
            keyHex, {
            iv: ivHex,
            mode: CryptoJS.mode.CBC,
            padding: CryptoJS.pad.Pkcs7
        }
        );
        return decrypted.toString(CryptoJS.enc.Utf8);
    }
}