/**
 * 
 */
package com.quantgroup.asset.distribution.util;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


/**
 * MD5Util
 */
public class MD5Util {
	private static final Logger logger = LoggerFactory.getLogger(MD5Util.class);
	
	public static void main(String[] args) {
		long timeunit = System.currentTimeMillis();
		String appkey = "qaaaaa";
        md5("timeunit=" + timeunit + "appkey=" + appkey);
	}
	/**
	 * md5加密
	 * @param content
	 * @return
	 */
	public static String md5(String content){
		StringBuffer md5StrBuff =null;
		try {
			MessageDigest md5 = MessageDigest.getInstance("md5");
			md5.update(content.getBytes());
			byte[] domain = md5.digest();
			md5StrBuff = new StringBuffer();
			for (int i = 0; i < domain.length; i++) {
				if (Integer.toHexString(0xFF & domain[i]).length() == 1) {
					md5StrBuff.append("0").append(Integer.toHexString(0xFF & domain[i]));
				} else{
					md5StrBuff.append(Integer.toHexString(0xFF & domain[i]));
				}
			}
		} catch (NoSuchAlgorithmException e) {
			logger.error("md5 encrypt exception",e);
		}
		return md5StrBuff.toString();
	}


}
