From cbfb868ec09c2b11ebd166dd281c2077b5bda15c Mon Sep 17 00:00:00 2001 From: wenc000 <450292408@qq.com> Date: Tue, 30 Jun 2020 00:27:42 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9EMD5Util?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/cm/common/utils/MD5Util.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 cloud-common/src/main/java/com/cm/common/utils/MD5Util.java diff --git a/cloud-common/src/main/java/com/cm/common/utils/MD5Util.java b/cloud-common/src/main/java/com/cm/common/utils/MD5Util.java new file mode 100644 index 0000000..1ce51a7 --- /dev/null +++ b/cloud-common/src/main/java/com/cm/common/utils/MD5Util.java @@ -0,0 +1,36 @@ +package com.cm.common.utils; + +import java.nio.charset.Charset; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; + +/** + * When you feel like quitting. Think about why you started + * 当你想要放弃的时候,想想当初你为何开始 + * + * @ClassName: MD5Util + * @Description: MD5处理 + * @Author: WangGeng + * @Date: 2020/6/30 12:20 上午 + * @Version: 1.0 + **/ +public class MD5Util { + + public static String toMD5String(String str) throws NoSuchAlgorithmException { + MessageDigest md = MessageDigest.getInstance("MD5"); + if (md != null && str != null) { + byte[] byteData = md.digest(str.getBytes(Charset.forName("UTF-8"))); + StringBuilder sb = new StringBuilder(); + byte[] var4 = byteData; + int var5 = byteData.length; + + for (int var6 = 0; var6 < var5; ++var6) { + byte aByteData = var4[var6]; + sb.append(Integer.toString((aByteData & 255) + 256, 16).substring(1)); + } + return sb.toString(); + } else { + return null; + } + } +}