Java MD5

public class test {
    public static void main(String[] args) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] digest = md5.digest("kk".getBytes(StandardCharsets.UTF_8));
        byte[] digest1 = md5.digest("ko".getBytes(StandardCharsets.UTF_8));
        System.out.println(toStr(digest));
        System.out.println(toStr(digest1));
    }

    public static String toStr(byte[] str) {
        StringBuilder stringBuilder = new StringBuilder();
        for (byte b : str) {
            String s = Integer.toHexString(b & 0xff);
            if (1==s.length()) {
                stringBuilder.append(0);
            }
            stringBuilder.append(s);
        }
        return stringBuilder.toString();
    }
}
String md5 = DigestUtils.md5DigestAsHex(content.getBytes(StandardCharsets.UTF_8));

你可能感兴趣的:(java,开发语言)