public static byte[] hex2Byte(String str, int byteLength) { byte[] second = hex2Byte(str); if (second.length >= byteLength) { return second; } // New Java arrays are zeroed: // http://docs.oracle.com/javase/specs/jls/se7/html/jls-4.html#jls-4.12.5 byte[] first = new byte[byteLength - second.length]; return Utils.concatAll(first, second); }