diff --git a/EasyTool.Core/CodeCategory/AesUtil.cs b/EasyTool.Core/SecureCategory/AesUtil.cs
similarity index 96%
rename from EasyTool.Core/CodeCategory/AesUtil.cs
rename to EasyTool.Core/SecureCategory/AesUtil.cs
index e2d2bb2..86f5737 100644
--- a/EasyTool.Core/CodeCategory/AesUtil.cs
+++ b/EasyTool.Core/SecureCategory/AesUtil.cs
@@ -1,14 +1,10 @@
using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Drawing;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
-using static System.Net.Mime.MediaTypeNames;
-namespace EasyTool.CodeCategory
+namespace EasyTool
{
public static class AesUtil
{
@@ -96,13 +92,13 @@ private static bool IsLegalSize(string sk)
/// 默认UTF8
/// 加密后的结果
///
- public static string Encrypt(string text, string key, string iv ,CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7, Encoding? encoding = null)
+ public static string Encrypt(string text, string key, string iv, CipherMode cipher = CipherMode.CBC, PaddingMode padding = PaddingMode.PKCS7, Encoding? encoding = null)
{
if (string.IsNullOrWhiteSpace(text))
return string.Empty; ;
- if (!KeyIsLegalSize(key))
+ if (!KeyIsLegalSize(key))
throw new ArgumentException("不合规的秘钥,请确认秘钥为16 、24、 32位的字符");
- if (!IvIsLegalSize(iv))
+ if (!IvIsLegalSize(iv))
throw new ArgumentException("不合规的iv,请确认iv为16位的字符");
encoding ??= Encoding.UTF8;
diff --git a/EasyTool.Core/CodeCategory/DesUtil.cs b/EasyTool.Core/SecureCategory/DesUtil.cs
similarity index 95%
rename from EasyTool.Core/CodeCategory/DesUtil.cs
rename to EasyTool.Core/SecureCategory/DesUtil.cs
index 94e350f..ac275bf 100644
--- a/EasyTool.Core/CodeCategory/DesUtil.cs
+++ b/EasyTool.Core/SecureCategory/DesUtil.cs
@@ -1,11 +1,9 @@
using System;
-using System.Collections.Generic;
-using System.IO;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
-namespace EasyTool.CodeCategory
+namespace EasyTool
{
///
/// DES工具类
@@ -78,7 +76,7 @@ public static string Decrypt(string str, string sk, CipherMode cipher = CipherMo
/// 默认UTF8
///
///
- public static string Encrypt(string str, string sk,string iv, CipherMode cipher = CipherMode.ECB, PaddingMode padding = PaddingMode.PKCS7, Encoding? encoding = null)
+ public static string Encrypt(string str, string sk, string iv, CipherMode cipher = CipherMode.ECB, PaddingMode padding = PaddingMode.PKCS7, Encoding? encoding = null)
{
if (string.IsNullOrWhiteSpace(str)) return string.Empty;
if (!IsLegalSize(sk)) throw new ArgumentException("不合规的秘钥,请确认秘钥为8位的字符");
diff --git a/EasyTool.Core/SecureCategory/MD5Utils.cs b/EasyTool.Core/SecureCategory/MD5Utils.cs
new file mode 100644
index 0000000..0c6a8f0
--- /dev/null
+++ b/EasyTool.Core/SecureCategory/MD5Utils.cs
@@ -0,0 +1,56 @@
+using EasyTool.ConvertCategory;
+using System.IO;
+using System.Security.Cryptography;
+using System.Text;
+
+namespace EasyTool
+{
+ ///
+ /// MD5加密工具类
+ ///
+ public class MD5Utils
+ {
+ ///
+ /// MD5加密
+ ///
+ /// 加密字符串
+ /// 是否小写
+ ///
+ public static string Encrypt(string source, bool lowerCase = false)
+ {
+ if (string.IsNullOrWhiteSpace(source))
+ return string.Empty;
+
+ return Encrypt(Encoding.UTF8.GetBytes(source), lowerCase);
+ }
+
+ ///
+ /// MD5加密
+ ///
+ /// 加密字节流
+ /// 是否小写
+ ///
+ public static string Encrypt(byte[] source, bool lowerCase = false)
+ {
+ if (source == null)
+ return string.Empty;
+
+ using var md5Hash = MD5.Create();
+ return md5Hash.ComputeHash(source).ToHex(lowerCase);
+ }
+
+ ///
+ /// MD5加密
+ ///
+ /// 流
+ /// 是否小写
+ ///
+ public static string Encrypt(Stream inputStream, bool lowerCase = false)
+ {
+ if (inputStream == null) return string.Empty;
+
+ using var md5Hash = MD5.Create();
+ return md5Hash.ComputeHash(inputStream).ToHex(lowerCase);
+ }
+ }
+}