wjc
2025-01-22 f88c3087f0e192b82b560db8d44423a2d46b4773
app/src/main/java/com/hdl/photovoltaic/utils/Md5Utils.java
@@ -8,13 +8,15 @@
import java.security.NoSuchAlgorithmException;
public class Md5Utils {
    /**
     * MD5转字符串
     */
    public static String encodeMD5(String s) {
    public static String encodeMD5(byte[] f) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(s.getBytes(StandardCharsets.UTF_8));
            digest.update(f);
            byte[] messageDigest = digest.digest();
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException e) {
@@ -22,6 +24,7 @@
        }
        return "";
    }
    private static String toHexString(byte[] keyData) {
        if (keyData == null) {
@@ -37,6 +40,21 @@
            sb.append(hexStr);
        }
        return sb.toString();
    }
    /**
     * MD5转字符串
     */
    public static String encodeMD5(String s) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(s.getBytes(StandardCharsets.UTF_8));
            byte[] messageDigest = digest.digest();
            return toHexString(messageDigest);
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return "";
    }
    /**
@@ -89,21 +107,21 @@
        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);
    }
//    /**
//     * 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);
//    }
}