From 4f3a98f19143865cdc1de4791e8a95d96bd40c65 Mon Sep 17 00:00:00 2001 From: maven <2163098428@qq.com> Date: 星期五, 01 八月 2025 13:27:59 +0800 Subject: [PATCH] yys 密码已重置 --- ruoyi-common/src/main/java/com/ruoyi/common/utils/Md5Util.java | 68 ++++++++++++++++++++++++++++++++++ 1 files changed, 68 insertions(+), 0 deletions(-) diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/utils/Md5Util.java b/ruoyi-common/src/main/java/com/ruoyi/common/utils/Md5Util.java new file mode 100644 index 0000000..a56ecf1 --- /dev/null +++ b/ruoyi-common/src/main/java/com/ruoyi/common/utils/Md5Util.java @@ -0,0 +1,68 @@ +package com.ruoyi.common.utils; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * @author cxf + */ +public class Md5Util { + /** + * 榛樿鐨勫瘑鐮佸瓧绗︿覆缁勫悎锛岀敤鏉ュ皢瀛楄妭杞崲鎴� 16 杩涘埗琛ㄧず鐨勫瓧绗� + */ + protected static char hexDigits[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'}; + protected static MessageDigest messagedigest = null; + + static { + try { + messagedigest = MessageDigest.getInstance("MD5"); + } catch (NoSuchAlgorithmException e) { + e.printStackTrace(); + } + } + + public static String getFileMd5String(File file) throws IOException { + InputStream fis; + fis = new FileInputStream(file); + byte[] buffer = new byte[1024]; + int numRead = 0; + while ((numRead = fis.read(buffer)) > 0) { + messagedigest.update(buffer, 0, numRead); + } + fis.close(); + return bufferToHex(messagedigest.digest()); + } + + public static String getStringMd5(String str) { + byte[] buffer = str.getBytes(); + messagedigest.update(buffer); + return bufferToHex(messagedigest.digest()); + } + + public static String bufferToHex(byte bytes[]) { + return bufferToHex(bytes, 0, bytes.length); + } + + private static String bufferToHex(byte bytes[], int m, int n) { + StringBuffer stringbuffer = new StringBuffer(2 * n); + int k = m + n; + for (int l = m; l < k; l++) { + appendHexPair(bytes[l], stringbuffer); + } + return stringbuffer.toString(); + } + + private static void appendHexPair(byte bt, StringBuffer stringbuffer) { + // 鍙栧瓧鑺備腑楂� 4 浣嶇殑鏁板瓧杞崲 + char c0 = hexDigits[(bt & 0xf0) >> 4]; + // 涓洪�昏緫鍙崇Щ锛屽皢绗﹀彿浣嶄竴璧峰彸绉�,姝ゅ鏈彂鐜颁袱绉嶇鍙锋湁浣曚笉鍚� + // 鍙栧瓧鑺備腑浣� 4 浣嶇殑鏁板瓧杞崲 + char c1 = hexDigits[bt & 0xf]; + stringbuffer.append(c0); + stringbuffer.append(c1); + } +} -- Gitblit v1.9.3