How to get MD5 hash in Java



How to get MD5 hashed string in java which is similar to MySQL MD5

SELECT MD5('md5string')


1.MD5 Using Class

MessageDigest.getInstance(String Algorithm)

And then keep on updating the message digest using update() function:
public void update(byte [] input)

digest function to generate a hash code:
public byte[] digest()

String password = "password";  
MessageDigest md = MessageDigest.getInstance("MD5");
byte[] digest = md.digest();
String myHash = DatatypeConverter

2.MD5 using Apache Commons

The class org.apache.commons.codec.digest.DigestUtils

String md5Hex = DigestUtils.md5Hex(password).toUpperCase();

3.MD5 using Guava
MD5 checksums using

String filename = "path/to/test_md5.txt";
HashCode hash =
  .hash(new File(filename), Hashing.md5());
String myChecksum = hash.toString()