十六进制字符串转字节数组
/*** 功能: 十六进制字符串转字节数组
*@paramhexString 十六进制字符串
*@return字节数组*/
public static byte[] convertHexStringToBytes(String hexString){//判空
if(hexString == null || hexString.length() == 0) {return null;
}//合法性校验
if(!hexString.matches("[a-fA-F0-9]*") || hexString.length() % 2 != 0) {return null;
}//计算
int mid = hexString.length() / 2;byte[]bytes = new byte[mid];for (int i = 0; i < mid; i++) {
bytes[i]= Integer.valueOf(hexString.substring(i * 2, i * 2 + 2), 16).byteValue();
}returnbytes;
}
字节数组转十六进制字符串
/*** 字节数组转16进制数
*@parambytes 字节数组
*@return返回值*/
public static String convertBytesToHexString(byte[]bytes) {
StringBuilder res= new StringBuilder("");for (byteaByte : bytes) { </