package com.pqs9900.util;

import com.njcn.utils.SM.SM4Utils;
import com.njcn.utils.ThreeDes;
import org.apache.commons.codec.binary.Base64;

/**
 * system
 *
 * @author cdf
 * @date 2021/10/12
 */
public class TerminalUtil {


    /**
     * cd 系统配置的加密解密方式
     * content 需要加密解密的内容
     * 解密对应内容
     * @author cdf
     * @date 2021/10/12
     */
    public static String decoderString(Integer cd,String content) throws Exception{
        String seriesTmp = null;
        if (cd == 0) {
            seriesTmp = Base64.decodeBase64(content).toString();
        } else if (cd == 1) {
            seriesTmp = ThreeDes.decryptThreeDes(content);
        } else if (cd == 2) {
            //SM4加密密码
            String secretkey = SM4Utils.globalSecretKey;
            SM4Utils sm4 = new SM4Utils(secretkey);
            seriesTmp = sm4.decryptData_ECB(content);
        }
        return seriesTmp;
    }

    /**
     *
     * cd 系统配置的加密解密方式
     * content 需要加密解密的内容
     * 加密对应内容
     * @author cdf
     * @date 2021/10/12
     */
    public static String encodeString(Integer cd,String content){
        String key = null;
        if (cd == 0) {
            key = Base64.encodeBase64String(content.getBytes());
        } else if (cd == 1) {
            key = ThreeDes.encryptThreeDes(content);
        } else if (cd == 2) {
            //SM4加密密码
            String secretkey = SM4Utils.globalSecretKey;
            SM4Utils sm4 = new SM4Utils(secretkey);
            key = sm4.encryptData_ECB(content);
        }
        return key;
    }

}
