1.将16进制字符串转换为字节数组再转base64

 public static void main(String[] args) {
 String data = "7d41f335c0e412a9c60343ab2395b3b0";
 System.out.println(encode(ByteConvertUtil.hexStringToByteArray(data)));
 }
    public static String encode(byte[] data) {
        return new BASE64Encoder().encode(data);
 }

2.转换工具类

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
 byte[] data = new byte[len / 2];
 for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                + Character.digit(s.charAt(i + 1), 16));
 }
    return data;
}

棘丶
12 声望1 粉丝