public String getMd5 ( String msg ) { MessageDigest md ; try { md = getMessageDigest ( ) ; byte [ ] hash = md . digest ( msg . getBytes ( StandardCharsets . UTF_8 ) ) ; //converting byte array to Hexadecimal String StringBuilder sb = new StringBuilder ( 2 * hash . length ) ; for ( byte b : hash ) { sb . append ( String . format ( "%02x" , b & 0xff ) ) ; } return sb . toString ( ) ; } catch ( NoSuchAlgorithmException ex ) { logger . error ( "Fail to get MD5 of String " + msg , ex ) ; } return null ; }
Create a md5 from string