This is useful for storing passwords in a database though still vulnerable to md5 dictionary attacks, anyway, here’s a static method.
public static String hash(String text) {
String hashedString = "";
try {
MessageDigest md5Hash = MessageDigest.getInstance("MD5");
md5Hash.update(text.getBytes(), 0, text.length());
hashedString = new BigInteger(1, md5Hash.digest()).toString(16);
} catch (NoSuchAlgorithmException exception) {
exception.printStackTrace();
}
return hashedString;
}
This will return the MD5 hash. Have a great day!
Comments