package com.jkcredit.invoice.hub.util;

import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;

/**
 * @description:
 * @author: xusonglin
 * @create: 2020/1/9 15:28
 * @version: V1.0
 **/
public class EncodeUtil {
    public static String getAppSecret(String appKey) {
        String keyStr = "hangzhou.junxin.risk" + appKey;
        try {
            MessageDigest sha = MessageDigest.getInstance("SHA");
            byte[] byteArray = keyStr.getBytes(StandardCharsets.UTF_8);
            byte[] md5Bytes = sha.digest(byteArray);
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16) {
                    hexValue.append("0");
                }
                hexValue.append(Integer.toHexString(val));
            }
            String singKey = hexValue.toString().toUpperCase();
            return singKey;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
}
