package com.winit.api.util;

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

public class MD5Util {

	/**
	 * 取得字符串的摘要信息
	 * @param input
	 * @return
	 */
	public static String getMd5(String input){
		byte[] out = null;
		try {
			MessageDigest md = MessageDigest.getInstance("MD5");
			md.update(input.getBytes());
			out = md.digest();
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return toHexString(out);
	}
	
	/**
	 * 转换成16进制
	 * @param out
	 * @return
	 */
	private static String toHexString(byte[] out) {
		StringBuffer buf = new StringBuffer();
		for(byte b:out){
			buf.append(String.format("%02X", b));
		}
		return buf.toString();
	}

}
