Java,MD5

来源:互联网 发布:传奇数据库下载 编辑:程序博客网 时间:2024/05/19 10:36
public static String md5(String target) {        try {            MessageDigest messageDigest = MessageDigest.getInstance("MD5");            byte[] bytes = messageDigest.digest(target.getBytes());            StringBuffer sb = new StringBuffer();            for (byte b : bytes) {                int i = b & 0xff;                String hexString = Integer.toHexString(i);                if (hexString.length() < 2) {                    hexString = "0" + hexString;                }                sb.append(hexString);            }            return sb.toString();        } catch (NoSuchAlgorithmException e) {            e.printStackTrace();        }        return null;    }
0 0