From 9539519f9d34069d734d544bd8e38a796ea1ecae Mon Sep 17 00:00:00 2001 From: luoyesiqiu Date: Thu, 4 Apr 2024 23:51:50 +0800 Subject: [PATCH] Merge message digest util classes --- .../java/com/luoye/dpt/util/Md5Utils.java | 16 -------------- .../luoye/dpt/util/MessageDigestUtils.java | 22 +++++++++++++++++++ .../java/com/luoye/dpt/util/ShaUtils.java | 20 ----------------- 3 files changed, 22 insertions(+), 36 deletions(-) delete mode 100644 dpt/src/main/java/com/luoye/dpt/util/Md5Utils.java delete mode 100644 dpt/src/main/java/com/luoye/dpt/util/ShaUtils.java diff --git a/dpt/src/main/java/com/luoye/dpt/util/Md5Utils.java b/dpt/src/main/java/com/luoye/dpt/util/Md5Utils.java deleted file mode 100644 index 0ccefad9..00000000 --- a/dpt/src/main/java/com/luoye/dpt/util/Md5Utils.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.luoye.dpt.util; - -/** - * @author luoyesiqiu - */ -public class Md5Utils extends MessageDigestUtils { - private static final String ALGORITHM = "md5"; - - public static String md5(byte[] input){ - return hash(ALGORITHM,input); - } - - public static String shortMd5(byte[] input){ - return md5(input).substring(8,24); - } -} diff --git a/dpt/src/main/java/com/luoye/dpt/util/MessageDigestUtils.java b/dpt/src/main/java/com/luoye/dpt/util/MessageDigestUtils.java index b753a345..dddbd65c 100644 --- a/dpt/src/main/java/com/luoye/dpt/util/MessageDigestUtils.java +++ b/dpt/src/main/java/com/luoye/dpt/util/MessageDigestUtils.java @@ -8,6 +8,8 @@ * @author luoyesiqiu */ public class MessageDigestUtils { + private static final String ALGORITHM_MD5 = "md5"; + private static final String ALGORITHM_SHA256 = "sha-256"; public static String hash(String algorithm,byte[] input){ StringBuilder ret = new StringBuilder(); try { @@ -26,4 +28,24 @@ public static String hash(String algorithm,byte[] input){ } return ret.toString(); } + + public static String md5(byte[] input){ + return hash(ALGORITHM_MD5,input); + } + + public static String shortMd5(byte[] input){ + return md5(input).substring(8,24); + } + + public static String sha256(byte[] input){ + return hash(ALGORITHM_SHA256,input); + } + + public static String shortSha256Left(byte[] input) { + return sha256(input).substring(0,32); + } + + public static String shortSha256Right(byte[] input) { + return sha256(input).substring(32,64); + } } diff --git a/dpt/src/main/java/com/luoye/dpt/util/ShaUtils.java b/dpt/src/main/java/com/luoye/dpt/util/ShaUtils.java deleted file mode 100644 index ba1cc5ab..00000000 --- a/dpt/src/main/java/com/luoye/dpt/util/ShaUtils.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.luoye.dpt.util; - -/** - * @author luoyesiqiu - */ -public class ShaUtils extends MessageDigestUtils{ - private static final String ALGORITHM = "sha-256"; - - public static String sha256(byte[] input){ - return hash(ALGORITHM,input); - } - - public static String shortSha256Left(byte[] input) { - return sha256(input).substring(0,32); - } - - public static String shortSha256Right(byte[] input) { - return sha256(input).substring(32,64); - } -}