package cn.com.easytaxi.util;

public class MD5
{
	public static String getMD5(byte[] source)
	{
		String s = null;
		char hexDigits[] = { // 用来将字节转换成 16 进制表示的字符
		'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
		try
		{
			java.security.MessageDigest md = java.security.MessageDigest.getInstance("MD5");
			md.update(source);
			byte tmp[] = md.digest(); // MD5 的计算结果是一个 128 位的长整数,
			// 用字节表示就是 16 个字节
			char str[] = new char[16 * 2]; // 每个字节用 16 进制表示的话,使用两个字符,
			// 所以表示成 16 进制需要 32 个字符
			int k = 0; // 表示转换结果中对应的字符位置
			for (int i = 0; i < 16; i++)
			{ // 从第一个字节开始,对 MD5 的每一个字节
				// 转换成 16 进制字符的转换
				byte byte0 = tmp[i]; // 取第 i 个字节
				str[k++] = hexDigits[byte0 >>> 4 & 0xf]; // 取字节中高 4 位的数字转换,
				// >>> 为逻辑右移,将符号位一起右移
				str[k++] = hexDigits[byte0 & 0xf]; // 取字节中低 4 位的数字转换
			}
			s = new String(str); // 换后的结果转换为字符串
			
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
		return s;
	}
	
	
	
	public static void main(String[] args)
	{
		
		
		System.out.println(getMD5("itolrgvh".getBytes()));
		
	}
	
	
}
最近下载更多
别碰我被窝  LV9 2021年10月25日
Myangyyyy  LV10 2021年3月5日
qwqzbl  LV6 2020年5月27日
123456nty  LV37 2020年5月13日
丶空城过客  LV12 2019年7月26日
wa8021110  LV9 2019年7月16日
张三的任命啊  LV2 2019年1月3日
aisc1314  LV14 2018年12月28日
wyx065747  LV67 2018年10月14日
我是黄老邪  LV10 2018年9月25日
最近浏览更多
许文欣  LV2 2022年3月26日
sodkj123  LV15 2021年10月26日
别碰我被窝  LV9 2021年10月25日
CoderMars  LV13 2021年8月23日
Myangyyyy  LV10 2021年3月5日
13043860zj  LV16 2021年2月24日
JIeless  LV2 2021年2月5日
2252536772  LV21 2021年2月4日
sssssssyy  LV10 2020年12月17日
最强之神  LV7 2020年8月14日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友