From 30859ca8f2175475d2c666353bc27f3b2ceede53 Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 22 八月 2024 13:43:47 +0800 Subject: [PATCH] 2024年08月22日13:43:45 --- app/src/main/java/com/hdl/photovoltaic/utils/Md5Utils.java | 52 +++++++++++++++++++++++++++++++++++----------------- 1 files changed, 35 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/hdl/photovoltaic/utils/Md5Utils.java b/app/src/main/java/com/hdl/photovoltaic/utils/Md5Utils.java index 34a1a39..a80b8ee 100644 --- a/app/src/main/java/com/hdl/photovoltaic/utils/Md5Utils.java +++ b/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); +// } } -- Gitblit v1.8.0