当前位置 : 主页 > 编程语言 > c++ >

Android计算字符串MD5值

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt public static String md5sum(String str) { MessageDigest mdEncoder; try { mdEncoder = MessageDigest.getInstance("MD5"); mdEncoder.update(str.getBytes(Charset.forName("US-ASCII")), 0, str.length()); StringBuilder hexString = new
gistfile1.txt
public static String md5sum(String str) {
        MessageDigest mdEncoder;
        try {
            mdEncoder = MessageDigest.getInstance("MD5");
            mdEncoder.update(str.getBytes(Charset.forName("US-ASCII")), 0, str.length());
            StringBuilder hexString = new StringBuilder();
            for (byte b : mdEncoder.digest()) {
                hexString.append(String.format("%02x", b&0xff));
            }
            return hexString.toString();
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
网友评论