/** * Convert a string of hex digits to a hash. * * @param s * string of hex digits * @return the hash value represented by the string */ public static byte[] stringToHash(String s) { if (s.length() % 2 != 0) { throw new IllegalArgumentException("Invalid hash string: " + s); } byte[] hash = new byte[s.length() / 2]; for (int i = 0; i < s.length(); i += 2) { byte b = (byte) ((hexDigitValue(s.charAt(i)) << 4) + hexDigitValue(s.charAt(i + 1))); hash[i / 2] = b; } return hash; }
/** * Convert a string of hex digits to a hash. * * @param s * string of hex digits * @return the hash value represented by the string */ public static byte[] stringToHash(String s) { if (s.length() % 2 != 0) { throw new IllegalArgumentException("Invalid hash string: " + s); } byte[] hash = new byte[s.length() / 2]; for (int i = 0; i < s.length(); i += 2) { byte b = (byte) ((hexDigitValue(s.charAt(i)) << 4) + hexDigitValue(s.charAt(i + 1))); hash[i / 2] = b; } return hash; }