1. 程式人生 > >java中MD5加密解密

java中MD5加密解密

package com.util;


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

import sun.misc.BASE64Encoder;

/**
 * MD5加密解密
 * @author HouYong
 *
 */
public class MD5Util {
	
	/**
	 * 加密
	 * @param message
	 * @return
	 */
	public static String encodeString(String message)
	{
		byte[] by = null;
		try {
			//獲取MD5加密演算法
			MessageDigest md = MessageDigest.getInstance("md5");
			by = md.digest(message.getBytes());
		} catch (NoSuchAlgorithmException e) {
			e.printStackTrace();
		}
		return new BASE64Encoder().encode(by);
	}
	
	/**
	 * 解密
	 * @param message
	 * @return
	 */
	public static String decodeString(String message)
	{
		return encodeString(message);
	}
}