package com.pj.utils.ht;

import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;

import javax.crypto.Cipher;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;

/**
 * AES加密工具类
 *
 * @author SCH
 * @since 2023-08-21 15:11:03
 */
public class AESUtil {
    /**
     * 日志相关
     */
    private static final Logger LOGGER = LoggerFactory.getLogger(AESUtil.class);
    /**
     * 编码
     */
    private static final String ENCODING = "UTF-8";
    /**
     * 算法定义
     */
    private static final String AES_ALGORITHM = "AES";
    /**
     * 指定填充方式
     */
    private static final String CIPHER_PADDING = "AES/ECB/PKCS5Padding";
    private static final String CIPHER_CBC_PADDING = "AES/CBC/PKCS5Padding";
    /**
     * 偏移量(CBC中使用，增强加密算法强度)
     */
    private static final String IV_SEED = "1234567812345678";

    /**
     * AES加密
     * @param content 待加密内容
     * @param aesKey  密码
     * @return
     */
    public static String encrypt(String content, String aesKey){
        if(StringUtils.isBlank(content)){
            LOGGER.info("AES encrypt: the content is null!");
            return null;
        }
        //判断秘钥是否为16位
        if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
            try {
                //对密码进行编码
                byte[] bytes = aesKey.getBytes(ENCODING);
                //设置加密算法，生成秘钥
                SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
                // "算法/模式/补码方式"
                Cipher cipher = Cipher.getInstance(CIPHER_PADDING);
                //选择加密
                cipher.init(Cipher.ENCRYPT_MODE, skeySpec);
                //根据待加密内容生成字节数组
                byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING));
                //返回base64字符串
                return Base64Utils.encodeToString(encrypted);
            } catch (Exception e) {
                LOGGER.info("AES encrypt exception:" + e.getMessage());
                throw new RuntimeException(e);
            }

        }else {
            LOGGER.info("AES encrypt: the aesKey is null or error!");
            return null;
        }
    }

    /**
     * 解密
     *
     * @param content 待解密内容
     * @param aesKey  密码
     * @return
     */
    public static String decrypt(String content, String aesKey){
        if(StringUtils.isBlank(content)){
            LOGGER.info("AES decrypt: the content is null!");
            return null;
        }
        //判断秘钥是否为16位
        if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
            try {
                //对密码进行编码
                byte[] bytes = aesKey.getBytes(ENCODING);
                //设置解密算法，生成秘钥
                SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
                // "算法/模式/补码方式"
                Cipher cipher = Cipher.getInstance(CIPHER_PADDING);
                //选择解密
                cipher.init(Cipher.DECRYPT_MODE, skeySpec);

                //先进行Base64解码
                byte[] decodeBase64 = Base64Utils.decodeFromString(content);

                //根据待解密内容进行解密
                byte[] decrypted = cipher.doFinal(decodeBase64);
                //将字节数组转成字符串
                return new String(decrypted, ENCODING);
            } catch (Exception e) {
                LOGGER.info("AES decrypt exception:" + e.getMessage());
                throw new RuntimeException(e);
            }

        }else {
            LOGGER.info("AES decrypt: the aesKey is null or error!");
            return null;
        }
    }

    /**
     * AES_CBC加密
     *
     * @param content 待加密内容
     * @param aesKey  密码
     * @return
     */
    public static String encryptCBC(String content, String aesKey){
        if(StringUtils.isBlank(content)){
            LOGGER.info("AES_CBC encrypt: the content is null!");
            return null;
        }
        //判断秘钥是否为16位
        if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
            try {
                //对密码进行编码
                byte[] bytes = aesKey.getBytes(ENCODING);
                //设置加密算法，生成秘钥
                SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
                // "算法/模式/补码方式"
                Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING);
                //偏移
                IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING));
                //选择加密
                cipher.init(Cipher.ENCRYPT_MODE, skeySpec, iv);
                //根据待加密内容生成字节数组
                byte[] encrypted = cipher.doFinal(content.getBytes(ENCODING));
                //返回base64字符串
                return Base64Utils.encodeToString(encrypted);
            } catch (Exception e) {
                LOGGER.info("AES_CBC encrypt exception:" + e.getMessage());
                throw new RuntimeException(e);
            }

        }else {
            LOGGER.info("AES_CBC encrypt: the aesKey is null or error!");
            return null;
        }
    }

    /**
     * AES_CBC解密
     *
     * @param content 待解密内容
     * @param aesKey  密码
     * @return
     */
    public static String decryptCBC(String content, String aesKey){
        if(StringUtils.isBlank(content)){
            LOGGER.info("AES_CBC decrypt: the content is null!");
            return null;
        }
        //判断秘钥是否为16位
        if(StringUtils.isNotBlank(aesKey) && aesKey.length() == 16){
            try {
                //对密码进行编码
                byte[] bytes = aesKey.getBytes(ENCODING);
                //设置解密算法，生成秘钥
                SecretKeySpec skeySpec = new SecretKeySpec(bytes, AES_ALGORITHM);
                //偏移
                IvParameterSpec iv = new IvParameterSpec(IV_SEED.getBytes(ENCODING));
                // "算法/模式/补码方式"
                Cipher cipher = Cipher.getInstance(CIPHER_CBC_PADDING);
                //选择解密
                cipher.init(Cipher.DECRYPT_MODE, skeySpec, iv);

                //先进行Base64解码
                byte[] decodeBase64 = Base64Utils.decodeFromString(content);

                //根据待解密内容进行解密
                byte[] decrypted = cipher.doFinal(decodeBase64);
                //将字节数组转成字符串
                return new String(decrypted, ENCODING);
            } catch (Exception e) {
                LOGGER.info("AES_CBC decrypt exception:" + e.getMessage());
                throw new RuntimeException(e);
            }

        }else {
            LOGGER.info("AES_CBC decrypt: the aesKey is null or error!");
            return "{}";
        }
    }

    public static void main(String[] args) {
        // AES支持三种长度的密钥：128位、192位、256位。
        // 代码中这种就是128位的加密密钥，16字节 * 8位/字节 = 128位。
        String random = "klfksd78974s1d4f";
        System.out.println("随机key:" + random);
        System.out.println();

        System.out.println("---------加密---------");
        String aesResult = encrypt("测试AES加密12", random);
        System.out.println("aes加密结果:" + aesResult);
        System.out.println();

        System.out.println("---------解密---------");
        String decrypt = decryptCBC("qBDBckgyS6+s+h+Jxsm0UPd+bAnaRcsRTxWGYs4tO9vPpI5KWrOPImPT8ZAGgebre9Cvq7HswQMWrcQudRbO+mUF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4E8zMCHJtn/ipciIaKRAIqyywqRCb+YaS+Vzq017yyQwb0hwz6ksXTsU3DjKn87F4FmNHXOUfhdAa7YumF8aChdbKj8FD7RTeVeCnyVVRt4jrt", random);
        System.out.println("aes解密结果:" + decrypt);
        System.out.println();

        /*

{
"msgId": "854613917409198080",   // 每次都要不同,否则报错
"appId": "shop01",    // 不用改
"dataType": "002",   // 根据第二步,选择类型
"msgTime": "2023-08-24 16:57:26",  // 不用改
"sign": "0aa1ba7c6bdbecbb1b1a53d59447f886",  // 不用改
"data": "......" //data参数从项目中 AESUtil类,234 - 246 行代码 寻找复制粘贴到这里
}


边民: CkB9nBTgtwQYyW+/luLX0BdXYHTdcBMnQRnN1BHVWDjXd1Gqt9Yl3M/lI5WxljI39cJa3XTmWT3WH/zQpG4AZsqbSb1TO8f43+UgdQRfJqChYy69B2JZsV0856REEBb7h89mYXyCTHl3eeImf/Ilw8Xq5XQ6cc0WV4/AltZLVj9AiCqi0YV2PY7FXjl6nP/gboh3T+Z+LxNmY/iTk5oUUhaIxt+PFitgkEkOeZrTP3NhLxtaAPwoFxDmPGSZEWWDLgJSdvJeYMUKPz+sL12ybzMVudqo6B2lYUDCWpcQ4L6pGJaXH7qBwUPyOxFn2Nf7FTHNxC3UkIrVNLeAfxf0CctLnnmJALY97bRQu7iuAcojh/zvQV91u3L4lek0xyiKSiVcNSdBbPG4zNPnv/ocWouphcV6IY2ncoP0RBQFVqsD9q5l5kC05q6XWqDkE3BM/WkqeWvh49epGb9SwUzoD0NpQXqqQAUpW0dE+KLWwb7QdWOi626epPZ9XxyJcyDS

商铺:
CkB9nBTgtwQYyW+/luLX0P7AN7AG9vhXlSNzkpfp33/HoZX6MjrrBrQnRJkKy1nOeahRTV90bkIZYymuy9iUlegyIOwF/W2eEBQTJqBde3zTZT9BLDiua1cdaS3vFsOuzB4VZ+jwkcmwppw18uscw8DDT0Ay/YHCXCalecLrlqYKu9Ahi3bX/0QqoKoI2x0Rx1rAObdsK22eBrbw+U82M4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9M


        */

        System.out.println("--------AES_CBC加密解密---------");
        String cbcResult = encryptCBC( "{\n" +
                        "\"platSeqNo\": \"YSB0000000011\",\n" +
                        "\"preNo\": \"PRENO00001\",\n" +
                        "\"itrdclDeclareId\": \"SB000000001\",\n" +
                        "\"declareId\": \"\",\n" +
                        "\"declareType\": \"1\",\n" +
                        "\"declareName\": \"陆毅\",\n" +
                        "\"ciphertextIdno\": \"45010218561212367u\",\n" +
                        "\"shopNo\": \"\",\n" +
                        "\"shopName\": \"\",\n" +
                        "\"orgPutrecNo\": \"\",\n" +
                        "\"orgName\": \"\",\n" +
                        "\"orgScc\": \"\",\n" +
                        "\"veNo\": \"云ABW888\",\n" +
                        "\"vehicleType\": \"4\",\n" +
                        "\"btrnbBizModecd\": \"03\",\n" +
                        "\"gFlow\": \"02\",\n" +
                        "\"iEFlag\": \"I\",\n" +
                        "\"fieldCode\": \"HS001\",\n" +
                        "\"fieldName\": \"杨柳岸市场\",\n" +
                        "\"customsCode\": \"GQ001\",\n" +
                        "\"carPool\": \"1\",\n" +
                        "\"note\": \"备注会后悔ddd\",\n" +
                        "\"sumAmt\": \"160000\",\n" +
                        "\"sumGrossWt\": \"230000\",\n" +
                        "\"sumNetWt\": \"220000\",\n" +
                        "\"trafMode\": \"大卡车\",\n" +
                        "\"currCode\": \"人民币\",\n" +
                        "\"packNo\": \"3\",\n" +
                        "\"tradeCountry\": \"越南\",\n" +
                        "\"mName\": \"LDJGQT加工企业\",\n" +
                        "\"mScc\": \"LDJGQTSHTYXXDM\",\n" +
                        "\"shareFlag\": \"0\",\n" +
                        "\"dclType\": \"申报单类型\",\n" +
                        "\"mdfblRvkRsn\": \"\",\n" +
                        "\"borderFlag\": \"边民备案编号标记\",\n" +
                        "\"delStatus\": \"启用\",\n" +
                        "\"declStatus\": \"已申报\",\n" +
                        "\"declTime\": \"2023-03-03\",\n" +
                        "\"rcptTime\": \"2023-04-04\",\n" +
                        "\"auditRemark\": \"审核备注\",\n" +
                        "\"agentCode\": \"YSGJDLQYDM\",\n" +
                        "\"manifestId\": \"YSGJPCH\",\n" +
                        "\"shopPutrecNo\": \"SHOPBEIANBIANHAO\",\n" +
                        "\"borderId\": \"边民id\",\n" +
                        "\"msgId\": \"\",\n" +
                        "\"entCode\": \"QIYECODE\",\n" +
                        "\"entName\": \"QIYENAME\",\n" +
                        "\"borderPeopleList\": [\n" +
                        "{\n" +
                        "\"platSeqNo\": \"YSBNO0000003\",\n" +
                        "\"borderNo\": \"111\",\n" +
                        "\"borderName\": \"陆毅\",\n" +
                        "\"ciphertextIdno\": \"45010218561212367u\",\n" +
                        "\"borderPutrecNo\": \"10000000000000003\",\n" +
                        "}\n" +
                        "],\n" +
                        "\"borderPeopleLimitList\": [\n" +
                        "{\n" +
                        "\"platSeqNo\": \"YSBNO0000003\",\n" +
                        "\"limitNo\": \"222\",\n" +
                        "\"borderName\": \"陆毅\",\n" +
                        "\"ciphertextIdno\": \"45010218561212367u\",\n" +
                        "\"borderPutrecNo\": \"10000000000000003\",\n" +
                        "\"codeTs\": \"GOODS001\",\n" +
                        "\"gName\": \"榴莲\",\n" +
                        "\"gLimit\": \"8000\",\n" +
                        "\"gGrossWt\": \"230000\",\n" +
                        "\"gNo\": \"01\",\n" +
                        "}\n" +
                        "],\n" +
                        "\"goodsList\": [\n" +
                        "{\n" +
                        "\"platSeqNo\": \"YSBNO0000003\",\n" +
                        "\"gNo\": \"01\",\n" +
                        "\"codeTs\": \"GOODS001\",\n" +
                        "\"gName\": \"榴莲\",\n" +
                        "\"gModel\": \"100斤/箱\",\n" +
                        "\"gQty\": \"7\",\n" +
                        "\"qty1\": \"7\",\n" +
                        "\"qty2\": \"7\",\n" +
                        "\"grossWt\": \"230000\",\n" +
                        "\"netWt\": \"220000\",\n" +
                        "\"originCountry\": \"越南\",\n" +
                        "\"gUnit\": \"箱\",\n" +
                        "\"unit1\": \"吨\",\n" +
                        "\"unit2\": \"柜\",\n" +
                        "\"declPrice\": \"10000\",\n" +
                        "\"declTotal\": \"160000\",\n" +
                        "\"storageEnvm\": \"1\",\n" +
                        "\"useTo\": \"出售\",\n" +
                        "\"shopNo\": \"SP001\",\n" +
                        "\"shopName\": \"什么景色都有杂货铺\",\n" +
                        "\"ciqCode\": \"检疫检疫代码\",\n" +
                        "\"ciqName\": \"检疫检疫名称\",\n" +
                        "\"wrapType\": \"包装类型\"\n" +
                        "}\n" +
                        "]\n" +
                        "}\n",
                "klfksd78974s1d4f"); // RabbitmQ.ACC_KEY
        System.out.println("aes_cbc加密结果:" + cbcResult);
        System.out.println();

        System.out.println("---------解密CBC---------");
        String cbcDecrypt = decryptCBC("zo5yvhKGlGI4DFIbdwOa2eDjupWkiKvfWDGdNIbpX3WbDq4LsUhnTYh6aLPdj+w4l6OmVzLEjgh2/FC8MVmkYqCT6MZ401A8I8h7JYNXr+FpBg7dvZ/DgFpZ5u6uhYGwpJW65Sq21L1ulf4u8gwqB5DsKhhplzpPgO5D/RAgTM7JtCeP8r14b8rMG0Ux5FDjD3Beg+84XgA38PCZaSH++TONfN3iUkhei6MHrCumncofsTP8TxXxK+qMuZDacD8BBx+boScXqFFG/SEJM0vcruq5ozw16Trg+bUHv5ZZsWVt7el1NySpx6LF49ajSUIFVfTNAtIEa1WZ78Yq+81V/u97PVXGBu52PssOm1vZFkYEBtobYJzoUEKvA9veNKPpQ85cl57HaXA9cLWjydoQItxyetmxAWLNDE2HKR5Q1+w=", "klfksd78974s1d4f");// RabbitmQ.ACC_KEY
        System.out.println("aes解密结果:" + cbcDecrypt);
        System.out.println();
    }


}
