package com.sjws.utils;
/**
* Created by Lenovo on 2019/3/11.
*/
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class Md5Utils {
/**
* md5加密算法
* @param text
*/
/**
* md5加密算法
*/
public static String encode(String text) {
try {
MessageDigest digest = MessageDigest.getInstance("md5");
// 加密转换
byte[] digest2 = digest.digest(text.getBytes());
StringBuffer sb = new StringBuffer();
for (byte b : digest2) {
int a = b & 0xff;// 取低8位 取正
String hexString = Integer.toHexString(a);
if (hexString.length() == 1) {
hexString = "0" + hexString;
}
sb.append(hexString);
}
return sb.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
}