OAuthCredentialHasher { public static String hashCredential(String credential) { if (credential == null) { return null; } try { MessageDigest digest = MessageDigest.getInstance("SHA-256"); byte[] hash = digest.digest(credential.getBytes(StandardCharsets.UTF_8)); String encodedHash = Base64.encodeBase64String(hash); return encodedHash; } catch (NoSuchAlgorithmException e) { throw new java.lang.IllegalStateException("unknown codec SHA-256", e); } } private  OAuthCredentialHasher(); static String hashCredential(String credential);  }
@Test public void testHashCredential() { String hashCredential = OAuthCredentialHasher.hashCredential("test"); assertEquals("n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg=", hashCredential); }
@Test public void testHashCredentialNull() { String hashCredential = OAuthCredentialHasher.hashCredential(null); assertNull(hashCredential); }