Java Image Requests

← Back

If you'd like an easy way of working with Gravatar, then check out , otherwise read on。

Things are a little complex in Java. The following class will provide you with a static method that returns the hex format md5 of an input string:

import java.util.*;
public class MD5Util {
  public static String hex(byte[] array) {
      StringBuffer sb = new StringBuffer();
      for (int i = 0; i < array.length; ++i) {
	      & 0xFF) | 0x100).substring(1,3));        
      return sb.toString();
  public static String md5Hex (String message) {
      try {
	  MessageDigest md = 
	  return hex (md.digest(message.getBytes("CP1252")));
      } catch (NoSuchAlgorithmException e) {
      } catch (UnsupportedEncodingException e) {
      return null;

This class can then be used to return the MD5 hash of an email address (make sure you lower case it first!) like this:

String email = "";
String hash = MD5Util.md5Hex(email);

With the hex string that is returned, you can construct your gravatar URL.

大发时时彩 吉林快3计划 湖南快乐十分走势 亿信彩票投注 500彩票网 大发时时彩 河北快3代理 159彩票 山东11选5开奖 大发时时彩