import org.slf4j.Logger; import org.slf4j.LoggerFactory;
import java.security.MessageDigest;
public class Md5Generation { private static final Logger LOG = LoggerFactory.getLogger(Md5Generation.class);
/** * 生成MD5 * [@param](http://my.oschina.net/u/2303379) login TShop登录名 * [@param](http://my.oschina.net/u/2303379) token TShop token * [@param](http://my.oschina.net/u/2303379) key 时间毫秒数 * [@return](http://my.oschina.net/u/556800) */public static String getKeyedDigest(String login, String token, String key) { try { String temp = login + token + key; MessageDigest md5 = MessageDigest.getInstance("MD5"); byte[] bytes = md5.digest(temp.getBytes()); return byteToHex(bytes); } catch (Exception e) { LOG.info("Md5Generation : generation MD5 Failed. "); } return null;}public static String byteToHex(byte[] bits) { if (bits == null) { return null; } StringBuffer hex = new StringBuffer(bits.length * 2); for (int i = 0; i < bits.length; i++) { if (((int) bits[i] & 0xff) < 0x10) { hex.append("0"); } hex.append(Integer.toString((int) bits[i] & 0xff, 16)); } return hex.toString();}
}