Java MD5加密

获取MD5字符串

 

 

public static String getMD5Str(String str) {
		MessageDigest messageDigest = null;
		try {
			messageDigest = MessageDigest.getInstance("MD5");
			messageDigest.reset();
			messageDigest.update(str.getBytes("UTF-8"));
		} catch (Exception e) {
			System.out.println("getMD5Str()=" + e.toString());
			System.exit(-1);
		}

		byte[] byteArray = messageDigest.digest();
		StringBuffer sb = new StringBuffer();
		String temp = "";
		for (int i = 0; i < byteArray.length; i++) {
			temp = Integer.toHexString(0xFF & byteArray[i]);
			if (temp.length() == 1) {
				sb.append(0);
			}
			sb.append(temp);
		}
		return sb.toString();
	}

你可能感兴趣的:(Java MD5加密)