/**
 * 文件名：Md5Util.java
 * 描述：MD5加密
 * 包名：cn.com.kmlt.monstarBase.utils.encrpt
 * 作者：WENJQ
 * 创建日期：2016年05月26日
 * 
 */
package com.mgq.base.utils.encrypt;

import java.security.MessageDigest;


public class Md5Util {

   	/****
	 * 
	 * MD5加密
	 * 
	 */
	public static String encrypt(String plainText) {
		try {

			String passwordString = plainText + "vision_ylssygp";

			MessageDigest md = MessageDigest.getInstance("SHA-1");
			md.update(passwordString.getBytes());
			byte b[] = md.digest();

			return bytesToHexString(b);

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

			return null;
		}
	}
	
	/**
	 * bytes 转化为字符串
	 * 
	 * **/
	public static String bytesToHexString(byte[] src) {
		StringBuilder stringBuilder = new StringBuilder("");
		if (src == null || src.length <= 0) {
			return null;
		}
		for (int i = 0; i < src.length; i++) {
			int v = src[i] & 0xFF;
			String hv = Integer.toHexString(v);
			if (hv.length() < 2) {
				stringBuilder.append(0);
			}
			stringBuilder.append(hv);
		}
		return stringBuilder.toString();
	}
   
}

