Created
May 30, 2012 22:09
-
-
Save estebanroblesluna/2839246 to your computer and use it in GitHub Desktop.
Compute md5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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