java 生成md5值

private static String getMD5(String info) {
    try {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        md5.update(info.getBytes("UTF-8"));
        byte[] md5Array = md5.digest();
        StringBuilder strBuilder = new StringBuilder();
		for (int i = 0; i < md5Array.length; i++) {
			int temp = 0xff & md5Array[i];
			String hexString = Integer.toHexString(temp);
			if (hexString.length() == 1) {
				strBuilder.append("0").append(hexString);
			} else {
				strBuilder.append(hexString);
			}
		}
    } catch (NoSuchAlgorithmException e) {
        return "";
    } catch (UnsupportedEncodingException e) {
        return "";
    }
	return strBuilder.toString();
}

猜你喜欢

转载自blog.csdn.net/qq_40393187/article/details/88877303