Skip to content

Instantly share code, notes, and snippets.

@omarmiatello
Created November 7, 2013 12:02
Show Gist options
  • Save omarmiatello/7353530 to your computer and use it in GitHub Desktop.
Save omarmiatello/7353530 to your computer and use it in GitHub Desktop.
private static String getCacheKey(String url, int maxWidth, int maxHeight) {
return md5(new StringBuilder(url.length() + 12).append("#W").append(maxWidth)
.append("#H").append(maxHeight).append(url).toString());
}
private static final String md5(final String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
throw new RuntimeException("Missing MD5?",e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment