@Test public void testHexStringToByteArray() throws URISyntaxException, FileNotFoundException, IOException { boolean dataTested = false; for (File file : AllCoreTest.getFilesFromResourceDir(AllCoreTest.TEST_DATA_ROOT)) { byte[] apacheBytes = DigestUtils.md5(new FileInputStream(file)); byte[] testBytes = DigestUtilities.hexStringToByteArray(DigestUtils.md5Hex(new FileInputStream(file))); assertArrayEquals("apacheBytes and testBytes should be equal", apacheBytes, testBytes); dataTested = true; } assertTrue("No data tested as flag no set", dataTested); }
public static byte[] hexStringToByteArray(String hexVal) { int len = hexVal.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexVal.charAt(i), 16) << 4) + Character .digit(hexVal.charAt(i + 1), 16)); } return data; }
DigestUtilities { public static byte[] hexStringToByteArray(String hexVal) { int len = hexVal.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexVal.charAt(i), 16) << 4) + Character .digit(hexVal.charAt(i + 1), 16)); } return data; } }
DigestUtilities { public static byte[] hexStringToByteArray(String hexVal) { int len = hexVal.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexVal.charAt(i), 16) << 4) + Character .digit(hexVal.charAt(i + 1), 16)); } return data; } private  DigestUtilities(); }
DigestUtilities { public static byte[] hexStringToByteArray(String hexVal) { int len = hexVal.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexVal.charAt(i), 16) << 4) + Character .digit(hexVal.charAt(i + 1), 16)); } return data; } private  DigestUtilities(); static final String byteDigestToHexString(byte[] digest); static byte[] hexStringToByteArray(String hexVal); static Set<String> getMessageDigestAlgorithmNames(); }
DigestUtilities { public static byte[] hexStringToByteArray(String hexVal) { int len = hexVal.length(); byte[] data = new byte[len / 2]; for (int i = 0; i < len; i += 2) { data[i / 2] = (byte) ((Character.digit(hexVal.charAt(i), 16) << 4) + Character .digit(hexVal.charAt(i + 1), 16)); } return data; } private  DigestUtilities(); static final String byteDigestToHexString(byte[] digest); static byte[] hexStringToByteArray(String hexVal); static Set<String> getMessageDigestAlgorithmNames();  }