MD5 Encryption in Java
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 encrypt(String text) {
String ecryptedText = "";
try {
MessageDigest md5Encrypt = MessageDigest.getInstance("MD5");
md5Encrypt.update(text.getBytes(), 0, text.length());
ecryptedText = new BigInteger(1, md5Encrypt.digest()).toString(16);
} catch (NoSuchAlgorithmException exception) {
exception.printStackTrace();
}
return ecryptedText;
}
This will return the MD5-encrypted string. Have a great day!

Hey, that was interesting,
but how can we prevent vulnerablity of md5 dictionary attacks?
Thanks for writing about it
Comment by software development uk — August 18, 2009 @ 3:58 pm