From 9af537d2a01da704ab270ea3018d8d58a94fd481 Mon Sep 17 00:00:00 2001
From: YaChengMu <1140049363@qq.com>
Date: Wed, 16 Jun 2021 19:47:26 +0800
Subject: [PATCH 1/5] =?UTF-8?q?Md5=E5=8A=A0=E5=AF=86=E6=96=B9=E6=B3=95?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E8=BD=AC=E5=A4=A7=E5=86=99?=
=?UTF-8?q?=E5=8F=82=E6=95=B0=20Md5=E5=8A=A0=E5=AF=86=E6=96=B9=E6=B3=95?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=98=AF=E5=90=A6=E8=BD=AC=E5=A4=A7=E5=86=99?=
=?UTF-8?q?=E5=8F=82=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Encryptions/MD5Encryption.cs | 26 +++++++++++++------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs b/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
index 1402456f1f..468af6b401 100644
--- a/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
+++ b/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
@@ -1,12 +1,12 @@
-// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// 让 .NET 开发更简单,更通用,更流行。
// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd.
//
// 框架名称:Furion
// 框架作者:百小僧
// 框架版本:2.8.9
-// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
-// Github:https://github.com/monksoul/Furion
+// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
+// Github:https://github.com/monksoul/Furion
// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE)
// -----------------------------------------------------------------------------
@@ -24,8 +24,16 @@ namespace Furion.DataEncryption
[SkipScan]
public static unsafe class MD5Encryption
{
+ ///
+ /// 小写
+ ///
private const uint LOWERCASING = 0x2020U;
+ ///
+ /// 大写
+ ///
+ private const uint UPPERCASING = 0;
+
private static readonly delegate* managed, Span, uint, void> _EncodeToUtf16Ptr;
[ThreadStatic]
@@ -49,10 +57,11 @@ namespace Furion.DataEncryption
///
/// 加密文本
/// MD5 字符串
+ /// 是否转大写,默认:false
/// bool
- public static bool Compare(string text, string hash)
+ public static bool Compare(string text, string hash, bool isUpper = false)
{
- var hashOfInput = Encrypt(text);
+ var hashOfInput = Encrypt(text, isUpper);
return hash.Equals(hashOfInput, StringComparison.OrdinalIgnoreCase);
}
@@ -60,15 +69,16 @@ namespace Furion.DataEncryption
/// MD5 加密
///
/// 加密文本
+ /// 是否转大写,默认:false
///
- public static string Encrypt(string text)
+ public static string Encrypt(string text, bool isUpper = false)
{
- return string.Create(32, text, static (p, q) =>
+ return string.Create(32, text, (p, q) =>
{
var buffer = Encoding.UTF8.GetBytes(q);
Span signed = stackalloc byte[16];
Instance.TryComputeHash(buffer, signed, out _);
- _EncodeToUtf16Ptr(signed, p, LOWERCASING);
+ _EncodeToUtf16Ptr(signed, p, isUpper ? LOWERCASING : UPPERCASING);
});
}
}
--
Gitee
From 4801e27c4638139db2f141715061a0b1a985d87f Mon Sep 17 00:00:00 2001
From: YaChengMu <1140049363@qq.com>
Date: Wed, 16 Jun 2021 19:48:43 +0800
Subject: [PATCH 2/5] =?UTF-8?q?DES=E5=8A=A0=E5=AF=86=E7=AE=97=E6=B3=95?=
=?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E9=83=A8MD5=E6=98=AF=E5=90=A6?=
=?UTF-8?q?=E8=BD=AC=E5=A4=A7=E5=86=99=E5=8F=82=E6=95=B0=20DES=E5=8A=A0?=
=?UTF-8?q?=E5=AF=86=E7=AE=97=E6=B3=95=E5=A2=9E=E5=8A=A0=E5=86=85=E9=83=A8?=
=?UTF-8?q?MD5=E6=98=AF=E5=90=A6=E8=BD=AC=E5=A4=A7=E5=86=99=E5=8F=82?=
=?UTF-8?q?=E6=95=B0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Encryptions/DESCEncryption.cs | 20 ++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/framework/Furion/DataEncryption/Encryptions/DESCEncryption.cs b/framework/Furion/DataEncryption/Encryptions/DESCEncryption.cs
index 897c4a5971..aaa78c6fd6 100644
--- a/framework/Furion/DataEncryption/Encryptions/DESCEncryption.cs
+++ b/framework/Furion/DataEncryption/Encryptions/DESCEncryption.cs
@@ -1,12 +1,12 @@
-// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// 让 .NET 开发更简单,更通用,更流行。
// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd.
//
// 框架名称:Furion
// 框架作者:百小僧
// 框架版本:2.8.9
-// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
-// Github:https://github.com/monksoul/Furion
+// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
+// Github:https://github.com/monksoul/Furion
// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE)
// -----------------------------------------------------------------------------
@@ -28,15 +28,16 @@ namespace Furion.DataEncryption
///
/// 加密文本
/// 密钥
+ /// 内部Md5加密是否转大写,默认:false
///
- public static string Encrypt(string text, string skey)
+ public static string Encrypt(string text, string skey, bool isUpper = false)
{
using var des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(text);
- des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
- des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
+ des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
+ des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
using var ms = new System.IO.MemoryStream();
using var cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
@@ -58,8 +59,9 @@ namespace Furion.DataEncryption
///
/// 加密后字符串
/// 密钥
+ /// 内部Md5加密是否转大写,默认:false
///
- public static string Decrypt(string hash, string skey)
+ public static string Decrypt(string hash, string skey, bool isUpper = false)
{
using var des = new DESCryptoServiceProvider();
int len;
@@ -73,8 +75,8 @@ namespace Furion.DataEncryption
inputByteArray[x] = (byte)i;
}
- des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
- des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
+ des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
+ des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
using var ms = new System.IO.MemoryStream();
using var cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
--
Gitee
From 11e302a19363f8b63d36a346dc27c9c73a72a461 Mon Sep 17 00:00:00 2001
From: YaChengMu <1140049363@qq.com>
Date: Wed, 16 Jun 2021 20:01:21 +0800
Subject: [PATCH 3/5] update
framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs.
---
framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs b/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
index 468af6b401..08a730406d 100644
--- a/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
+++ b/framework/Furion/DataEncryption/Encryptions/MD5Encryption.cs
@@ -78,7 +78,7 @@ namespace Furion.DataEncryption
var buffer = Encoding.UTF8.GetBytes(q);
Span signed = stackalloc byte[16];
Instance.TryComputeHash(buffer, signed, out _);
- _EncodeToUtf16Ptr(signed, p, isUpper ? LOWERCASING : UPPERCASING);
+ _EncodeToUtf16Ptr(signed, p, isUpper ? UPPERCASING : LOWERCASING);
});
}
}
--
Gitee
From de8c6d444aed86286e1d5f92e772d4c05ee8d633 Mon Sep 17 00:00:00 2001
From: YaChengMu <1140049363@qq.com>
Date: Wed, 16 Jun 2021 20:02:09 +0800
Subject: [PATCH 4/5] update
framework/Furion.Pure/DataEncryption/Encryptions/MD5Encryption.cs.
---
.../Encryptions/MD5Encryption.cs | 26 +++++++++++++------
1 file changed, 18 insertions(+), 8 deletions(-)
diff --git a/framework/Furion.Pure/DataEncryption/Encryptions/MD5Encryption.cs b/framework/Furion.Pure/DataEncryption/Encryptions/MD5Encryption.cs
index 1402456f1f..08a730406d 100644
--- a/framework/Furion.Pure/DataEncryption/Encryptions/MD5Encryption.cs
+++ b/framework/Furion.Pure/DataEncryption/Encryptions/MD5Encryption.cs
@@ -1,12 +1,12 @@
-// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// 让 .NET 开发更简单,更通用,更流行。
// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd.
//
// 框架名称:Furion
// 框架作者:百小僧
// 框架版本:2.8.9
-// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
-// Github:https://github.com/monksoul/Furion
+// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
+// Github:https://github.com/monksoul/Furion
// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE)
// -----------------------------------------------------------------------------
@@ -24,8 +24,16 @@ namespace Furion.DataEncryption
[SkipScan]
public static unsafe class MD5Encryption
{
+ ///
+ /// 小写
+ ///
private const uint LOWERCASING = 0x2020U;
+ ///
+ /// 大写
+ ///
+ private const uint UPPERCASING = 0;
+
private static readonly delegate* managed, Span, uint, void> _EncodeToUtf16Ptr;
[ThreadStatic]
@@ -49,10 +57,11 @@ namespace Furion.DataEncryption
///
/// 加密文本
/// MD5 字符串
+ /// 是否转大写,默认:false
/// bool
- public static bool Compare(string text, string hash)
+ public static bool Compare(string text, string hash, bool isUpper = false)
{
- var hashOfInput = Encrypt(text);
+ var hashOfInput = Encrypt(text, isUpper);
return hash.Equals(hashOfInput, StringComparison.OrdinalIgnoreCase);
}
@@ -60,15 +69,16 @@ namespace Furion.DataEncryption
/// MD5 加密
///
/// 加密文本
+ /// 是否转大写,默认:false
///
- public static string Encrypt(string text)
+ public static string Encrypt(string text, bool isUpper = false)
{
- return string.Create(32, text, static (p, q) =>
+ return string.Create(32, text, (p, q) =>
{
var buffer = Encoding.UTF8.GetBytes(q);
Span signed = stackalloc byte[16];
Instance.TryComputeHash(buffer, signed, out _);
- _EncodeToUtf16Ptr(signed, p, LOWERCASING);
+ _EncodeToUtf16Ptr(signed, p, isUpper ? UPPERCASING : LOWERCASING);
});
}
}
--
Gitee
From e907bb64072b796cd7209b45ec2e6a35514a4e5c Mon Sep 17 00:00:00 2001
From: YaChengMu <1140049363@qq.com>
Date: Wed, 16 Jun 2021 20:03:12 +0800
Subject: [PATCH 5/5] update
framework/Furion.Pure/DataEncryption/Encryptions/DESCEncryption.cs.
---
.../Encryptions/DESCEncryption.cs | 20 ++++++++++---------
1 file changed, 11 insertions(+), 9 deletions(-)
diff --git a/framework/Furion.Pure/DataEncryption/Encryptions/DESCEncryption.cs b/framework/Furion.Pure/DataEncryption/Encryptions/DESCEncryption.cs
index 897c4a5971..aaa78c6fd6 100644
--- a/framework/Furion.Pure/DataEncryption/Encryptions/DESCEncryption.cs
+++ b/framework/Furion.Pure/DataEncryption/Encryptions/DESCEncryption.cs
@@ -1,12 +1,12 @@
-// -----------------------------------------------------------------------------
+// -----------------------------------------------------------------------------
// 让 .NET 开发更简单,更通用,更流行。
// Copyright © 2020-2021 Furion, 百小僧, Baiqian Co.,Ltd.
//
// 框架名称:Furion
// 框架作者:百小僧
// 框架版本:2.8.9
-// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
-// Github:https://github.com/monksoul/Furion
+// 源码地址:Gitee: https://gitee.com/dotnetchina/Furion
+// Github:https://github.com/monksoul/Furion
// 开源协议:Apache-2.0(https://gitee.com/dotnetchina/Furion/blob/master/LICENSE)
// -----------------------------------------------------------------------------
@@ -28,15 +28,16 @@ namespace Furion.DataEncryption
///
/// 加密文本
/// 密钥
+ /// 内部Md5加密是否转大写,默认:false
///
- public static string Encrypt(string text, string skey)
+ public static string Encrypt(string text, string skey, bool isUpper = false)
{
using var des = new DESCryptoServiceProvider();
byte[] inputByteArray;
inputByteArray = Encoding.Default.GetBytes(text);
- des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
- des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
+ des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
+ des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
using var ms = new System.IO.MemoryStream();
using var cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write);
@@ -58,8 +59,9 @@ namespace Furion.DataEncryption
///
/// 加密后字符串
/// 密钥
+ /// 内部Md5加密是否转大写,默认:false
///
- public static string Decrypt(string hash, string skey)
+ public static string Decrypt(string hash, string skey, bool isUpper = false)
{
using var des = new DESCryptoServiceProvider();
int len;
@@ -73,8 +75,8 @@ namespace Furion.DataEncryption
inputByteArray[x] = (byte)i;
}
- des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
- des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey).Substring(0, 8));
+ des.Key = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
+ des.IV = Encoding.ASCII.GetBytes(MD5Encryption.Encrypt(skey, isUpper).Substring(0, 8));
using var ms = new System.IO.MemoryStream();
using var cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write);
--
Gitee