/*
 * Decompiled with CFR 0.152.
 */
package com.hst.taxService.util;

import com.hst.hwface.utils.Base64;
import com.hst.taxService.util.MD5Util;
import java.nio.ByteBuffer;
import java.nio.charset.Charset;
import java.util.BitSet;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

public class SecurityUtil {
    public static final String speedBilling = "F59E1B2970D64B8F926E9932E0A1A1DB";
    public static String app_secret = "627FAC5875AA4D00";
    public static String app_rate = "10";
    public static String url = "http://sdk.jss.com.cn/openPlatform/services";
    private static final BitSet UNRESERVED = new BitSet(256);
    private static final BitSet URLENCODER = new BitSet(256);
    private static final BitSet PUNCT = new BitSet(256);
    private static final BitSet USERINFO = new BitSet(256);
    private static final BitSet PATHSAFE = new BitSet(256);
    private static final BitSet URIC = new BitSet(256);
    private static final BitSet RESERVED = new BitSet(256);

    static {
        int i = 97;
        while (i <= 122) {
            UNRESERVED.set(i);
            ++i;
        }
        i = 65;
        while (i <= 90) {
            UNRESERVED.set(i);
            ++i;
        }
        i = 48;
        while (i <= 57) {
            UNRESERVED.set(i);
            ++i;
        }
        UNRESERVED.set(95);
        UNRESERVED.set(45);
        UNRESERVED.set(46);
        UNRESERVED.set(42);
        URLENCODER.or(UNRESERVED);
        UNRESERVED.set(33);
        UNRESERVED.set(126);
        UNRESERVED.set(39);
        UNRESERVED.set(40);
        UNRESERVED.set(41);
        PUNCT.set(44);
        PUNCT.set(59);
        PUNCT.set(58);
        PUNCT.set(36);
        PUNCT.set(38);
        PUNCT.set(43);
        PUNCT.set(61);
        USERINFO.or(UNRESERVED);
        USERINFO.or(PUNCT);
        PATHSAFE.or(UNRESERVED);
        PATHSAFE.set(47);
        PATHSAFE.set(59);
        PATHSAFE.set(58);
        PATHSAFE.set(64);
        PATHSAFE.set(38);
        PATHSAFE.set(61);
        PATHSAFE.set(43);
        PATHSAFE.set(36);
        PATHSAFE.set(44);
        RESERVED.set(59);
        RESERVED.set(47);
        RESERVED.set(63);
        RESERVED.set(58);
        RESERVED.set(64);
        RESERVED.set(38);
        RESERVED.set(61);
        RESERVED.set(43);
        RESERVED.set(36);
        RESERVED.set(44);
        RESERVED.set(91);
        RESERVED.set(93);
        URIC.or(RESERVED);
        URIC.or(UNRESERVED);
    }

    public static String urlEncode(String content, String charsetStr) {
        Charset charset = Charset.forName(charsetStr);
        if (content == null) {
            return null;
        }
        StringBuilder buf = new StringBuilder();
        ByteBuffer bb = charset.encode(content);
        while (bb.hasRemaining()) {
            int b = bb.get() & 0xFF;
            if (URLENCODER.get(b)) {
                buf.append((char)b);
                continue;
            }
            if (b == 32) {
                buf.append('+');
                continue;
            }
            buf.append("%");
            char hex1 = Character.toUpperCase(Character.forDigit(b >> 4 & 0xF, 16));
            char hex2 = Character.toUpperCase(Character.forDigit(b & 0xF, 16));
            buf.append(hex1);
            buf.append(hex2);
        }
        return buf.toString();
    }

    public static Object AESEncrypt(String sSrc, String sKey) {
        try {
            if (sKey == null) {
                System.out.print("Key\u4e3a\u7a7a");
                throw new Exception();
            }
            if (sKey.length() != 16) {
                System.out.print("Key\u957f\u5ea6\u4e0d\u7b49\u4e8e16\u4f4d");
                throw new Exception();
            }
            byte[] raw = sKey.getBytes("utf-8");
            SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
            cipher.init(1, skeySpec);
            byte[] encrypted = cipher.doFinal(sSrc.getBytes("utf-8"));
            new Base64();
            return Base64.encode(encrypted);
        }
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static Object AESDecrypt(String sSrc, String sKey) {
        block5: {
            block4: {
                try {
                    if (sKey != null) break block4;
                    return null;
                }
                catch (Exception ex) {
                    ex.printStackTrace();
                    return null;
                }
            }
            if (sKey.length() == 16) break block5;
            return null;
        }
        byte[] raw = sKey.getBytes("UTF-8");
        SecretKeySpec skeySpec = new SecretKeySpec(raw, "AES");
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
        cipher.init(2, skeySpec);
        new Base64();
        byte[] encrypted1 = Base64.decode(sSrc);
        byte[] original = cipher.doFinal(encrypted1);
        String originalString = new String(original, "utf-8");
        return originalString;
    }

    public static String MD5Encrypt(String randomSixNum) {
        String signidSource = new StringBuffer(randomSixNum).append(speedBilling).toString();
        String signidTarget = MD5Util.toMD5(signidSource);
        return signidTarget;
    }
}
