Andrew Andrew - 1 month ago 8x
Java Question

Convert MD5 array to String java

I know that there is a lot of similar topics, but still... can someone provide me a working example of method which generates MD5 String.

I'm currently using MessageDigest, and I'm doing the following to get a string


I guess there is some better way to do that.

Thanks in advance!

import java.math.*;

String toEnc = "Hash This!"; // Value to hash
MessageDigest mdEnc = MessageDigest.getInstance("MD5"); 
mdEnc.update(toEnc.getBytes(), 0, toEnc.length());
String md5 = new BigInteger(1, mdEnc.digest()).toString(16); // Hash value