@Test public void testGetHash() { System.out.println("getHash"); String password = "test"; String expResult = "098f6bcd4621d373cade4e832627b4f6"; String result = MD5Util.getHash(password); assertEquals(expResult, result); }
public static String getHash(String password) throws AuthException { byte[] passwordByteArr; try { passwordByteArr = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); md.reset(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } byte[] thedigest = md.digest(passwordByteArr); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < thedigest.length; i++) { String hexByte = Integer.toHexString(0xFF & thedigest[i]); if(hexByte.length()==1) { hexString.append('0'); } hexString.append(hexByte); } return hexString.toString(); }
MD5Util { public static String getHash(String password) throws AuthException { byte[] passwordByteArr; try { passwordByteArr = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); md.reset(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } byte[] thedigest = md.digest(passwordByteArr); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < thedigest.length; i++) { String hexByte = Integer.toHexString(0xFF & thedigest[i]); if(hexByte.length()==1) { hexString.append('0'); } hexString.append(hexByte); } return hexString.toString(); } }
MD5Util { public static String getHash(String password) throws AuthException { byte[] passwordByteArr; try { passwordByteArr = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); md.reset(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } byte[] thedigest = md.digest(passwordByteArr); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < thedigest.length; i++) { String hexByte = Integer.toHexString(0xFF & thedigest[i]); if(hexByte.length()==1) { hexString.append('0'); } hexString.append(hexByte); } return hexString.toString(); }  }
MD5Util { public static String getHash(String password) throws AuthException { byte[] passwordByteArr; try { passwordByteArr = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); md.reset(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } byte[] thedigest = md.digest(passwordByteArr); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < thedigest.length; i++) { String hexByte = Integer.toHexString(0xFF & thedigest[i]); if(hexByte.length()==1) { hexString.append('0'); } hexString.append(hexByte); } return hexString.toString(); }  static String getHash(String password); }
MD5Util { public static String getHash(String password) throws AuthException { byte[] passwordByteArr; try { passwordByteArr = password.getBytes("UTF-8"); } catch (UnsupportedEncodingException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } MessageDigest md; try { md = MessageDigest.getInstance("MD5"); md.reset(); } catch (NoSuchAlgorithmException e) { LOGGER.error(e.getLocalizedMessage(), e); throw new AuthException(e.getLocalizedMessage(), e); } byte[] thedigest = md.digest(passwordByteArr); StringBuilder hexString = new StringBuilder(); for (int i = 0; i < thedigest.length; i++) { String hexByte = Integer.toHexString(0xFF & thedigest[i]); if(hexByte.length()==1) { hexString.append('0'); } hexString.append(hexByte); } return hexString.toString(); }  static String getHash(String password);  }