@Test public void shouldHashNullPasswordToNull() { assertThat(hash(null), is(nullValue())); }
public static String hash(String plainText) { String hashValue = null; if (plainText == null) return null; try { MessageDigest msgDigest = MessageDigest.getInstance(PASSWORD_HASH_ALGORITHM); msgDigest.update(plainText.getBytes(PASSWORD_HASH_ENCODING)); byte rawByte[] = msgDigest.digest(); byte[] encodedBytes = Base64.encodeBase64(rawByte); return base64ToBase62(new String(encodedBytes)); } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } return hashValue; }
Encoder { public static String hash(String plainText) { String hashValue = null; if (plainText == null) return null; try { MessageDigest msgDigest = MessageDigest.getInstance(PASSWORD_HASH_ALGORITHM); msgDigest.update(plainText.getBytes(PASSWORD_HASH_ENCODING)); byte rawByte[] = msgDigest.digest(); byte[] encodedBytes = Base64.encodeBase64(rawByte); return base64ToBase62(new String(encodedBytes)); } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } return hashValue; } }
Encoder { public static String hash(String plainText) { String hashValue = null; if (plainText == null) return null; try { MessageDigest msgDigest = MessageDigest.getInstance(PASSWORD_HASH_ALGORITHM); msgDigest.update(plainText.getBytes(PASSWORD_HASH_ENCODING)); byte rawByte[] = msgDigest.digest(); byte[] encodedBytes = Base64.encodeBase64(rawByte); return base64ToBase62(new String(encodedBytes)); } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } return hashValue; }  }
Encoder { public static String hash(String plainText) { String hashValue = null; if (plainText == null) return null; try { MessageDigest msgDigest = MessageDigest.getInstance(PASSWORD_HASH_ALGORITHM); msgDigest.update(plainText.getBytes(PASSWORD_HASH_ENCODING)); byte rawByte[] = msgDigest.digest(); byte[] encodedBytes = Base64.encodeBase64(rawByte); return base64ToBase62(new String(encodedBytes)); } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } return hashValue; }  static String hash(String plainText); }
Encoder { public static String hash(String plainText) { String hashValue = null; if (plainText == null) return null; try { MessageDigest msgDigest = MessageDigest.getInstance(PASSWORD_HASH_ALGORITHM); msgDigest.update(plainText.getBytes(PASSWORD_HASH_ENCODING)); byte rawByte[] = msgDigest.digest(); byte[] encodedBytes = Base64.encodeBase64(rawByte); return base64ToBase62(new String(encodedBytes)); } catch (UnsupportedEncodingException e) { } catch (NoSuchAlgorithmException e) { } return hashValue; }  static String hash(String plainText);  }