使用Apache的Hex类实现Hex(16进制字符串和)和字节数组的互转

包名称:org.apache.commons.codec.binary

类名称:org.apache.commons.codec.binary.Hex

1、字节数组(byte[])转为十六进制(Hex)字符串

public static String byte2hex(byte[] input) {
    return Hex.encodeHexString(input);
}

2、十六进制字符串(Hex)转字节数字(byte[])

public static byte[] hex2byte(String input) {
    return Hex.decodeHex(input.toCharArray());
}
原文地址:https://www.cnblogs.com/frankyou/p/6068828.html