yangys
2024-05-07 9b677ea5c6978788d135fc15da3d78c5a93789c2
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();
    }
}