package com.nooice.library.utils;
import java.security.MessageDigest;
/**
* @describe <MD5加密> */public class MD5Util { private static final String ENCODING = "UTF-8";// 编码格式// md5加密
public static String md5(String string) { try { byte[] source = string.getBytes(ENCODING);//把要加密的字符串先拆分成byte[]数组 MessageDigest md = MessageDigest.getInstance("MD5");//MessageDigest类通过getinstance传入算法名称“MD5”得到其对象 byte[] md5Bytes = md.digest(source);//把准备好的byte数组通过digest方法获得新的散列码 StringBuilder builder = new StringBuilder();//可以看成字符串容器 for (byte b : md5Bytes) {//把加密后的散列码转换成字符串连接起来 builder.append(Integer.toString((b & 0xff) + 0x100, 16).substring(1));//把byte转化成32位16进制的字符串}
return builder.toString(); } catch (Exception e) { e.printStackTrace(); return ""; } }}