@TestFactory Stream<DynamicTest> testHex2byte() { return Stream.of("01AF0F1E", "00", "FF") .map(h -> dynamicTest(h, () -> assertEquals(h, HashUtils.byte2hex(HashUtils.hex2byte(h))))); }
public static byte[] hex2byte(String hex) { int bytes = hex.length() / 2; if (hex.length() - 2 * bytes != 0) { String msg = "Length of hex must be divisible by 2"; LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{msg, hex}); throw new IllegalArgumentException(msg); } byte[] byteArray = new byte[bytes]; for (int i = 0; i < bytes; i++) { byteArray[i] = (byte) ((Character.digit(hex.charAt(2 * i), 16) << 4) + Character.digit(hex.charAt(2 * i + 1), 16)); } return byteArray; }
HashUtils { public static byte[] hex2byte(String hex) { int bytes = hex.length() / 2; if (hex.length() - 2 * bytes != 0) { String msg = "Length of hex must be divisible by 2"; LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{msg, hex}); throw new IllegalArgumentException(msg); } byte[] byteArray = new byte[bytes]; for (int i = 0; i < bytes; i++) { byteArray[i] = (byte) ((Character.digit(hex.charAt(2 * i), 16) << 4) + Character.digit(hex.charAt(2 * i + 1), 16)); } return byteArray; } }
HashUtils { public static byte[] hex2byte(String hex) { int bytes = hex.length() / 2; if (hex.length() - 2 * bytes != 0) { String msg = "Length of hex must be divisible by 2"; LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{msg, hex}); throw new IllegalArgumentException(msg); } byte[] byteArray = new byte[bytes]; for (int i = 0; i < bytes; i++) { byteArray[i] = (byte) ((Character.digit(hex.charAt(2 * i), 16) << 4) + Character.digit(hex.charAt(2 * i + 1), 16)); } return byteArray; }  }
HashUtils { public static byte[] hex2byte(String hex) { int bytes = hex.length() / 2; if (hex.length() - 2 * bytes != 0) { String msg = "Length of hex must be divisible by 2"; LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{msg, hex}); throw new IllegalArgumentException(msg); } byte[] byteArray = new byte[bytes]; for (int i = 0; i < bytes; i++) { byteArray[i] = (byte) ((Character.digit(hex.charAt(2 * i), 16) << 4) + Character.digit(hex.charAt(2 * i + 1), 16)); } return byteArray; }  static byte[] getShaHash(String input); static byte[] hashPassword(String password, 
          byte[] salt, 
          int iterations, 
          int keyLength); static String byte2hex(byte[] byteArray); static byte[] hex2byte(String hex); }
HashUtils { public static byte[] hex2byte(String hex) { int bytes = hex.length() / 2; if (hex.length() - 2 * bytes != 0) { String msg = "Length of hex must be divisible by 2"; LOGGER.log(Level.SEVERE, "{0}: {1}", new Object[]{msg, hex}); throw new IllegalArgumentException(msg); } byte[] byteArray = new byte[bytes]; for (int i = 0; i < bytes; i++) { byteArray[i] = (byte) ((Character.digit(hex.charAt(2 * i), 16) << 4) + Character.digit(hex.charAt(2 * i + 1), 16)); } return byteArray; }  static byte[] getShaHash(String input); static byte[] hashPassword(String password, 
          byte[] salt, 
          int iterations, 
          int keyLength); static String byte2hex(byte[] byteArray); static byte[] hex2byte(String hex);  }