Skip to content

Instantly share code, notes, and snippets.

@romanr
Forked from estebanroblesluna/ComputeMD5.java
Created June 2, 2012 05:10
Show Gist options
  • Save romanr/2856691 to your computer and use it in GitHub Desktop.
Save romanr/2856691 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