HashUtil { public static String hashInBase64(final String s, final String algo) throws NoSuchAlgorithmException { return base64FromUtf8Bytes(MessageDigest.getInstance(algo) .digest(s.getBytes(StandardCharsets.UTF_8))); } private  HashUtil(); static String hashSHA256(final String s); static String hashSHA384(final String s); static String hashSHA512(final String s); static String base64FromUtf8Bytes(final byte[] bytes); static String hashInBase64(final String s, final String algo); static final String SHA_512; static final String SHA_384; static final String SHA_256; }
@Test public void testHashInBase64() throws NoSuchAlgorithmException { assertEquals("Kh8K+0/ZGGUJz40u7V2q+zTMKqFqV9HMsCyef9n9aPs=", HashUtil.hashInBase64("Hello webfirmframework", "SHA-256")); assertEquals("RZDeMlkNh7DS5dfofurW+copvbLj4QY7W/03wLIo2jI33mqXF2xDNbKXnumstQOS", HashUtil.hashInBase64("Hello webfirmframework", "SHA-384")); assertEquals("ghMAt8A5BbfxVoJuLHe/Kg8InW4UDyJH9pCM6T7xTo6WngUisFwvrn62TWu6IvYJKHhwKhKqFeY8+s9zSXQJ2g==", HashUtil.hashInBase64("Hello webfirmframework", "SHA-512")); }