public class MD5
{
//md5()信息摘要, 不可逆
public static String getMD5ofStr(String inbuf) throws Exception
{
Java.security.MessageDigest alg =
Java.security.MessageDigest.getInstance("MD5"); //or "SHA-1"
alg.update(inbuf.getBytes());
return byte2hex(alg.digest());
}
//字节码转换成16进制字符串
public static String byte2hex(byte[] b)
{
String hs = "";
String stmp = "";
for (int n = 0; n < b.length; n++)
{
stmp = (java.lang.Integer.toHexString(b[n] & 0XFF));
if (stmp.length() == 1)
hs = hs + "0" + stmp;
else
hs = hs + stmp;
}
return hs;
}
}
posted on 2006-10-18 13:27
周锐 阅读(812)
评论(0) 编辑 收藏 所属分类:
Java