package utils;
import java.security.MessageDigest;
public class MD5Utils
{
private static char hexDigist[] = {'0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f'};
public static String encode( String s )
{
try {
MessageDigest md = MessageDigest.getInstance("MD5");
md.update( s.getBytes() );
byte[] datas = md.digest(); //16个字节的长整数
char[] str = new char[2*16];
int k = 0;
for(int i=0;i<16;i++){
byte b = datas[i];
str[k++] = hexDigist[b>>>4 & 0xf];//高4位
str[k++] = hexDigist[b & 0xf];//低4位
}
s = new String(str);
return s;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
}
Java加密篇(2)-MD5
最新推荐文章于 2024-08-23 15:54:50 发布