Skip to content

Instantly share code, notes, and snippets.

@rturowicz
Created March 23, 2013 13:05
Show Gist options
  • Save rturowicz/5227665 to your computer and use it in GitHub Desktop.
Save rturowicz/5227665 to your computer and use it in GitHub Desktop.
MessageDigest digest;
byte[] hash;
String name = "http://test.com/d0d5689be9f9c8b5.jpg";
try {
digest = java.security.MessageDigest.getInstance("MD5");
digest.update(name.getBytes("UTF-8"));
hash = digest.digest();
BigInteger bigInt = new BigInteger(1, hash);
String hashtext = bigInt.toString(16);
while(hashtext.length() < 32 ){
hashtext = "0"+hashtext;
}
System.out.println(hashtext);
} catch (NoSuchAlgorithmException e1) {
e1.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment