public static String toMD5str(String str)

  String md5string="";

  try

  MessageDigest algorithm =MessageDigest.getInstance("MD5");

  algorithm.reset();

 algorithm.update(str.getBytes("utf-8"));

md5string=toHexString(algorithm.digest());

catch(NoSuchAlgorithmException e)

    throw new RuntimeException

catch(UnsupportEncodingException e)

e.printStackTrace();

return md5string;

 

 

public static String toHexString(byte[] bytes)

StringBuilder hexString=new StringBuilder();

for (int b : bytes) {
   if (b < 0){
    b += 256;
   }
   if (b < 16){
    hexString.append("0");    
   }
   hexString.append(Integer.toHexString(b));
  }
  return hexString.toString();