public class MD5Util {
public static void main(String[] args) {
String string = "0006410822李仕文园区/李仕文大厦/1单元/1层/大门12017-07-03 12:16:352017-07-04 00:00:002017-07-04 23:59:59";
String s = getMD5(string);
System.out.println(s);
}
public static String getMD5(String plainText) {
try {
MessageDigest md = MessageDigest.getInstance("MD5");//获取MD5实例
md.update(plainText.getBytes("utf-8"));//此处传入要加密的byte类型值
byte[] digest = md.digest();//此处得到的是md5加密后的byte类型值
int i;
StringBuilder sb = new StringBuilder();
for (int offset = 0; offset < digest.length; offset++) {
i = digest[offset];
if (i < 0){
i += 256;
}
if (i < 16){
sb.append(0);
}
sb.append(Integer.toHexString(i).toUpperCase());//通过Integer.toHexString方法把值变为16进制
}
return sb.toString();//从下标0开始,length目的是截取多少长度的值
} catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
}
Java MD5加密
最新推荐文章于 2023-09-28 08:02:44 发布