mac
2023-12-26 637e3152e3bfea430ca774c7dd178b4b9696c37f
HDLLinkPMSdk/src/main/java/com/hdl/linkpm/sdk/utils/HDLMD5Utils.java
@@ -4,6 +4,7 @@
import java.io.FileInputStream;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
@@ -12,16 +13,31 @@
 */
public final class HDLMD5Utils {
    /**
     * MD5转字符串
     */
    public static String encodeMD5(byte[] f) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(f);
            byte[] messageDigest = digest.digest();
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
     * MD5转字符串
     */
    public static String encodeMD5(String s) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(s.getBytes("UTF-8"));
            digest.update(s.getBytes(StandardCharsets.UTF_8));
            byte[] messageDigest = digest.digest();
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException | UnsupportedEncodingException e) {
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
@@ -50,7 +66,7 @@
    public static String encodeMD52(String s) {
        char[] hexDigits = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
        try {
            byte[] btInput = s.getBytes("utf-8");
            byte[] btInput = s.getBytes(StandardCharsets.UTF_8);
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(btInput);
            byte[] md = digest.digest();
@@ -93,21 +109,7 @@
        return bigInt.toString(16);
    }
    /**
     * MD5文件转字符串
     */
    public static String encodeMD5(byte[] f) {
        MessageDigest digest;
        try {
            digest = MessageDigest.getInstance("MD5");
            digest.update(f);
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
        BigInteger bigInt = new BigInteger(1, digest.digest());
        return bigInt.toString(16);
    }