yangys
2024-05-09 014ac34ff2baf657c3236f41fdbf11c9d7d414b4
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
package com.qianwen.smartman.modules.dnc.util;
 
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
 
public class StringMd5HashCode {
    public static String getMd5(String text) throws NoSuchAlgorithmException {
        MessageDigest md5 = MessageDigest.getInstance("MD5");
        byte[] bytes = md5.digest(text.getBytes(StandardCharsets.UTF_8));
        StringBuilder builder = new StringBuilder();
        for (byte aByte : bytes) {
            builder.append(Integer.toHexString((255 & aByte) | (-256)).substring(6));
        }
        return builder.toString();
    }
}