Here you can find the source of toByteArray(String hexStr)
private static byte[] toByteArray(String hexStr)
//package com.java2s; //License from project: Apache License public class Main { private static byte[] toByteArray(String hexStr) { if (hexStr.length() < 1) return null; byte[] result = new byte[hexStr.length() / 2]; for (int i = 0; i < hexStr.length() / 2; i++) { int high = Integer.parseInt(hexStr.substring(i * 2, i * 2 + 1), 16); int low = Integer.parseInt(hexStr.substring(i * 2 + 1, i * 2 + 2), 16); result[i] = (byte) (high * 16 + low); }/*from w w w. ja v a2 s .c o m*/ return result; } }