package com.gree.mall.manager.utils.refund;


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

public class AESUtil {

    /**
     * 密钥算法
     */
    private static final String ALGORITHM = "AES";
    /**
     * 加解密算法/工作模式/填充方式
     */
    private static final String ALGORITHM_MODE_PADDING = "AES/ECB/PKCS5Padding";
    /**
     * 生成key TODO
     */
//    private static SecretKeySpec key = new SecretKeySpec(MD5.MD5Encode(WeChatLogic.SECURE_KEY).toLowerCase().getBytes(), ALGORITHM);
    private static SecretKeySpec key = null;

    /**
     * AES加密
     *
     * @param data
     * @return
     * @throws Exception
     */
    public static String encryptData(String data) throws Exception {
        // 创建密码器
        Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
        // 初始化
        cipher.init(Cipher.ENCRYPT_MODE, key);
        return Base64Util.encode(cipher.doFinal(data.getBytes()));
    }

    /**
     * AES解密
     *
     * @param base64Data
     * @return
     * @throws Exception
     */
    public static String decryptData(String base64Data) throws Exception {
        Cipher cipher = Cipher.getInstance(ALGORITHM_MODE_PADDING);
        cipher.init(Cipher.DECRYPT_MODE, key);
        return new String(cipher.doFinal(Base64Util.decode(base64Data)));
    }

    public static void main(String[] args) throws Exception {
        //解密
        String req_info = "Zwl9G9N5Ypw5/X/sgkQaQ7UjjsoT3so+sn6J6pAuGMlzSy9PwHXWCs1S6VP8XMjC6UYdaa3zQD8FfYYvawzuk6eygpjRJ3p3tldtL61RUwxL8l4RPMXzooUVA3gwwJnhM6AbbpEcAbcHZtdCVHV66zwpvmCjLo+XhRhejBM2ye9iUU630INsKytLpS0FLJqPeDNug1v++NiLPcmhNDgqWA0TvTSeu72357bJ9nZUw79unNR5RAF4axOtqWb57wwNwx5t43qCw5WFCqR0O/A2/8IS//WNrVqaUbPVwMKAYcow27DP6NIhO2snoF77FZjUkoHJYTeMPW+mevaHoIQwtU84CRMAr0kFS+OBsV53R1Hqj4rzoHjuXRMRq/KyocPkYYGCBqmDjI1hET3gsYEmCakcPmYMM6QZMNweo1f+tW5AXqGsiZFiTqHzhdaZEGmCAuIaqwiQPLOSVeJECFwaebMi5e1Ebg4AmRSVrq/hOKtddmuClrFnP2jYvdAAKT7PwTqmqYzXuN0EUbz9fKKwcm9YoZ5gsN3CaFw60uQn8FIQlAhBIfyp+bKkt9XiqI/dwHpYY0Hvd6c/Ko9A4vPELCkMN3A5cwOlyYF/3Z3n+i9ScLRKKtMPPs+2wVsI8dZeluqCL8oiZqSzPtr+wjFj6pXxN6V9yWQOqLUEUbBRyhcf9OrcLX5y9LpMYMe1FpLIwGc+ojgqAv4WjIYJDRHAXUAZS9iERBnQAVgTU58XsM4HCoEIyvOGMJrIdciDdy9Uf0cX1l0VDUXaaxMV9MK3E4pGMjhg3NsKkt8S5w33XhmK+z1bv5bzsOltgbktCR9R4owsJwnGhb+CwwOPP5mdyc+2pP3hYxkylxVyVWgoFhIS5xpK33MBb8c6MR1yJx7+NFPljL8ZfcVsdLRwNkjsZBqw9RfU8ErhwBnoZ+Li6WHwj8YdYbxQdrEzNkXL+1XmsfHCILz707TytUXMRgkgWQhdUOLZAY6EL/t/3aXS6l8LqBKjwT6c+Kqjg6aanbZ16iV587zAQzkgTKXoUyv6mYflTws0El+TnYhdwzuq5nI=";
        String B = AESUtil.decryptData(req_info);
        System.out.println(B);

    }


    }
