MD5使用

MD5使用
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;
    }
}

你可能感兴趣的:(MD5使用)