首页>代码>ssm开发大学校园兼职平台项目(可以作为毕设)>/moonlighting/src/com/work/common/utils/MD5Util.java
package com.work.common.utils;

import java.security.MessageDigest;
import java.util.UUID;

public class MD5Util {

	private static String byteArrayToHexString(byte b[]) {
		StringBuffer resultSb = new StringBuffer();
		for (int i = 0; i < b.length; i++)
			resultSb.append(byteToHexString(b[i]));

		return resultSb.toString();
	}

	private static String byteToHexString(byte b) {
		int n = b;
		if (n < 0)
			n += 256;
		int d1 = n / 16;
		int d2 = n % 16;
		return hexDigits[d1] + hexDigits[d2];
	}

	public static String MD5Encode(String origin, String charsetname) {
		String resultString = null;
		try {
			resultString = new String(origin);
			MessageDigest md = MessageDigest.getInstance("MD5");
			if (charsetname == null || "".equals(charsetname))
				resultString = byteArrayToHexString(md.digest(resultString
						.getBytes()));
			else
				resultString = byteArrayToHexString(md.digest(resultString
						.getBytes(charsetname)));
		} catch (Exception exception) {
		}
		return resultString;
	}
	/**
	 * 获得16个长度的十六进制的UUID
	 * 
	 * @return UUID
	 */
	public static String get16UUID() {
		UUID id = UUID.randomUUID();
		String[] idd = id.toString().split("-");
		return idd[0] + idd[1] + idd[2];
	}

	private static final String hexDigits[] = { "0", "1", "2", "3", "4", "5",
			"6", "7", "8", "9", "a", "b", "c", "d", "e", "f" };
}
最近下载更多
leipengshen  LV8 2024年12月27日
翻斗花园胡英俊  LV2 2024年12月8日
bridge_44  LV2 2024年10月28日
穿山甲1001  LV6 2024年9月12日
TY0165  LV20 2024年6月21日
微信网友_7024879466991616  LV2 2024年6月6日
yyhrhv  LV8 2024年5月31日
吞吞吐吐她  LV6 2024年4月21日
860421  LV3 2024年4月18日
zolscy  LV24 2024年3月24日
最近浏览更多
chengguo123 4月2日
暂无贡献等级
哪里的完整版  LV8 3月10日
暂无贡献等级
暂无贡献等级
mymzmymzhhuu 1月5日
暂无贡献等级
leipengshen  LV8 2024年12月27日
2435058517 2024年12月2日
暂无贡献等级
短巷拥猫  LV12 2024年12月2日
暂无贡献等级
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友