How to get MD5 hash in Java

java
md5

#1

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

SELECT MD5('md5string')


#2

1.MD5 Using java.security.MessageDigest 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");
md.update(password.getBytes());
byte[] digest = md.digest();
String myHash = DatatypeConverter
          .printHexBinary(digest).toUpperCase();

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 com.google.common.io.Files.hash

String filename = "path/to/test_md5.txt";
     
HashCode hash = com.google.common.io.Files
  .hash(new File(filename), Hashing.md5());
String myChecksum = hash.toString()
  .toUpperCase();