关于使用MD5加密方法

来源:互联网 发布:断开连接的网络驱动器 编辑:程序博客网 时间:2024/05/22 14:06

关于使用MD5加密方法

public class MD5Util {    //32位加密方法    public static String md5_32(String str) {        byte[] hash;        try {            //字符串的报文摘要            hash = MessageDigest.getInstance("MD5").digest(str.getBytes("UTF-8"));        } catch (NoSuchAlgorithmException e) {           e.printStackTrace();        } catch (UnsupportedEncodingException e) {           e.printStackTrace();        }        StringBuffer hex = new StringBuffer();        for (byte b : hash) {            if ((b & 0xFF) < 0x10) hex.append("0");            hex.append(Integer.toHexString(b & 0xFF));        }        return hex.toString();    }    //采用16位加密方法    public static String md5_16(String str){        return md5(str).substring(8,24);    }}
0 0
原创粉丝点击