package com.ruoyi.common.utils;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.DES;

public class DesUtil {
    //info:需要加密的明文
    public String encrypt(String secretKey, String info) { //SecureUtil SymmetricAlgorithm
        //byte[] key = SecureUtil.generateKey(SymmetricAlgorithm.DES.getValue()).getEncoded();
        //String secretKey = new BASE64Encoder().encodeBuffer(key);  //SecureUtil

//        byte[] key = new byte[0];
//        try {
//            key = new BASE64Decoder().decodeBuffer(secretKey);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        DES des = SecureUtil.des(secretKey.getBytes());
        String encrypt = des.encryptHex(info);
        return encrypt;
    }


    //encrypt:需要解密的密文
    public static String decode(String secretKey, String encrypt) {
//        byte[] key = new byte[0];
//        try {
//            key = new BASE64Decoder().decodeBuffer(secretKey);
//        } catch (IOException e) {
//            e.printStackTrace();
//        }
        DES des = SecureUtil.des(secretKey.getBytes());
        return des.decryptStr(encrypt);
    }

}
