@Test public void test() throws BaleenException { assertEquals( "2cf24dba5fb0a30e26e83b2ac5b9e29e1b161e5c1fa7425e73043362938b9824", IdentityUtils.hashStrings("hello")); assertEquals( "185f8db32271fe25f561a6fc938b2e264306ec304eda518007d1764826381969", IdentityUtils.hashStrings("Hello")); assertEquals( "872e4e50ce9990d8b041330c47c9ddd11bec6b503ae9386a99da8584e9bb12c4", IdentityUtils.hashStrings("Hello", "World")); assertEquals("", IdentityUtils.hashStrings((String[]) null)); }
public static String hashStrings(String... strings) throws BaleenException { if (strings == null) { return ""; } StringBuilder hash = new StringBuilder(); StringBuilder concat = new StringBuilder(); for (String s : strings) { if (s != null) { concat.append(s); } } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.reset(); byte[] buffer = concat.toString().getBytes(StandardCharsets.UTF_8); md.update(buffer); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { hash.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { throw new BaleenException("Can't get MessageDigest instance for constructing hashes", e); } return hash.toString(); }
IdentityUtils { public static String hashStrings(String... strings) throws BaleenException { if (strings == null) { return ""; } StringBuilder hash = new StringBuilder(); StringBuilder concat = new StringBuilder(); for (String s : strings) { if (s != null) { concat.append(s); } } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.reset(); byte[] buffer = concat.toString().getBytes(StandardCharsets.UTF_8); md.update(buffer); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { hash.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { throw new BaleenException("Can't get MessageDigest instance for constructing hashes", e); } return hash.toString(); } }
IdentityUtils { public static String hashStrings(String... strings) throws BaleenException { if (strings == null) { return ""; } StringBuilder hash = new StringBuilder(); StringBuilder concat = new StringBuilder(); for (String s : strings) { if (s != null) { concat.append(s); } } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.reset(); byte[] buffer = concat.toString().getBytes(StandardCharsets.UTF_8); md.update(buffer); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { hash.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { throw new BaleenException("Can't get MessageDigest instance for constructing hashes", e); } return hash.toString(); } private  IdentityUtils(); }
IdentityUtils { public static String hashStrings(String... strings) throws BaleenException { if (strings == null) { return ""; } StringBuilder hash = new StringBuilder(); StringBuilder concat = new StringBuilder(); for (String s : strings) { if (s != null) { concat.append(s); } } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.reset(); byte[] buffer = concat.toString().getBytes(StandardCharsets.UTF_8); md.update(buffer); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { hash.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { throw new BaleenException("Can't get MessageDigest instance for constructing hashes", e); } return hash.toString(); } private  IdentityUtils(); static IdentityUtils getInstance(); long getNewId(); static String hashStrings(String... strings); }
IdentityUtils { public static String hashStrings(String... strings) throws BaleenException { if (strings == null) { return ""; } StringBuilder hash = new StringBuilder(); StringBuilder concat = new StringBuilder(); for (String s : strings) { if (s != null) { concat.append(s); } } try { MessageDigest md = MessageDigest.getInstance("SHA-256"); md.reset(); byte[] buffer = concat.toString().getBytes(StandardCharsets.UTF_8); md.update(buffer); byte[] digest = md.digest(); for (int i = 0; i < digest.length; i++) { hash.append(Integer.toString((digest[i] & 0xff) + 0x100, 16).substring(1)); } } catch (NoSuchAlgorithmException e) { throw new BaleenException("Can't get MessageDigest instance for constructing hashes", e); } return hash.toString(); } private  IdentityUtils(); static IdentityUtils getInstance(); long getNewId(); static String hashStrings(String... strings);  }