Skip to content

Instantly share code, notes, and snippets.

@estebanroblesluna
Created May 30, 2012 22:09
Show Gist options
  • Save estebanroblesluna/2839246 to your computer and use it in GitHub Desktop.
Save estebanroblesluna/2839246 to your computer and use it in GitHub Desktop.
Compute md5
import org.apache.commons.lang.StringUtils;
private String computeMD5(String string) throws NoSuchAlgorithmException {
byte[] stringBytes = string.getBytes();
MessageDigest messageDigest = MessageDigest.getInstance("MD5");
messageDigest.update(stringBytes, 0, stringBytes.length);
String md5 = new BigInteger(1, messageDigest.digest()).toString(16);
md5 = StringUtils.leftPad(md5, 32, '0');
return md5;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment