浏览代码

修正RSA签名的bug

懒得勤快 2 年之前
父节点
当前提交
22b58deeb8

+ 1 - 1
Masuit.Tools.Abstractions/Masuit.Tools.Abstractions.csproj

@@ -3,7 +3,7 @@
         <TargetFrameworks>netstandard2.0;netstandard2.1;net461;net5;net6;net7</TargetFrameworks>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <Version>2.6</Version>
+        <Version>2.6.0.1</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools基础公共库,包含一些常用的操作类,大都是静态类,加密解密,反射操作,Excel简单导出,权重随机筛选算法,分布式短id,表达式树,linq扩展,文件压缩,多线程下载和FTP客户端,硬件信息,字符串扩展方法,日期时间扩展操作,中国农历,大文件拷贝,图像裁剪,验证码,断点续传,集合扩展等常用封装。</Description>
         <Copyright>懒得勤快,长空X</Copyright>

+ 5 - 22
Masuit.Tools.Abstractions/Security/RSA.cs

@@ -8,7 +8,7 @@ namespace Masuit.Tools.Security
     /// <summary>
     /// RSA操作类
     /// </summary>
-    public class RSA
+    internal class RSA
     {
         /// <summary>
         /// 导出XML格式密钥对,如果convertToPublic含私钥的RSA将只返回公钥,仅含公钥的RSA不受影响
@@ -42,7 +42,6 @@ namespace Masuit.Tools.Security
             return new RsaPem(RSAObject, convertToPublic);
         }
 
-
         /// <summary>
         /// 加密字符串(utf-8),出错抛异常
         /// </summary>
@@ -89,22 +88,16 @@ namespace Masuit.Tools.Security
                 return null;
             }
 
-            byte[] byts = null;
             try
             {
-                byts = Convert.FromBase64String(str);
+                var bytes = Convert.FromBase64String(str);
+                var val = DecryptOrNull(bytes);
+                return val == null ? null : Encoding.UTF8.GetString(val);
             }
             catch
-            {
-            }
-
-            if (byts == null)
             {
                 return null;
             }
-
-            var val = DecryptOrNull(byts);
-            return val == null ? null : Encoding.UTF8.GetString(val);
         }
 
         /// <summary>
@@ -190,7 +183,6 @@ namespace Masuit.Tools.Security
             }
         }
 
-
         /// <summary>
         /// 最底层的RSACryptoServiceProvider对象
         /// </summary>
@@ -211,10 +203,6 @@ namespace Masuit.Tools.Security
         /// </summary>
         public RSA(int keySize)
         {
-            //var rsaParams = new CspParameters()
-            //{
-            //    Flags = CspProviderFlags.UseMachineKeyStore
-            //};
             RSAObject = new RSACryptoServiceProvider(keySize);
         }
 
@@ -229,12 +217,7 @@ namespace Masuit.Tools.Security
             }
             else
             {
-                //var rsaParams = new CspParameters
-                //{
-                //    Flags = CspProviderFlags.UseMachineKeyStore
-                //};
                 RSAObject = new RSACryptoServiceProvider();
-
                 RSAObject.FromXmlString(key);
             }
         }
@@ -247,4 +230,4 @@ namespace Masuit.Tools.Security
             RSAObject = pem.GetRSA();
         }
     }
-}
+}

+ 70 - 70
Masuit.Tools.Abstractions/Security/RSACrypt.cs

@@ -22,7 +22,7 @@ namespace Masuit.Tools.Security
         /// <param name="type">密钥类型</param>
         /// <param name="length">密钥长度</param>
         /// <returns></returns>
-        public static RsaKey GenerateRsaKeys(RsaKeyType type = RsaKeyType.XML, int length = 1024)
+        public static RsaKey GenerateRsaKeys(RsaKeyType type = RsaKeyType.PKCS8, int length = 1024)
         {
             var rsa = new RSA(length);
             return type switch
@@ -54,48 +54,48 @@ namespace Masuit.Tools.Security
         /// RSA的加密函数 string
         /// </summary>
         /// <param name="publicKey">公钥</param>
-        /// <param name="mStrEncryptString">需要加密的字符串</param>
+        /// <param name="value">需要加密的字符串</param>
         /// <returns>加密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSAEncrypt(this string mStrEncryptString, string publicKey)
+        public static string RSAEncrypt(this string value, string publicKey)
         {
             var rsa = new RSA(publicKey);
-            return rsa.Encrypt(mStrEncryptString);
+            return rsa.Encrypt(value);
         }
 
         /// <summary>
         /// RSA的加密函数 string
         /// </summary>
-        /// <param name="mStrEncryptString">需要加密的字符串</param>
+        /// <param name="value">需要加密的字符串</param>
         /// <returns>加密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSAEncrypt(this string mStrEncryptString)
+        public static string RSAEncrypt(this string value)
         {
-            return RSAEncrypt(mStrEncryptString, RsaKey.PublicKey);
+            return RSAEncrypt(value, RsaKey.PublicKey);
         }
 
         /// <summary>
         /// RSA的加密函数 byte[]
         /// </summary>
-        /// <param name="encryptString">需要加密的字节数组</param>
+        /// <param name="data">需要加密的字节数组</param>
         /// <param name="publicKey">公钥</param>
         /// <returns>加密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSAEncrypt(this byte[] encryptString, string publicKey)
+        public static string RSAEncrypt(this byte[] data, string publicKey)
         {
             var rsa = new RSA(publicKey);
-            return Convert.ToBase64String(rsa.Encrypt(encryptString));
+            return Convert.ToBase64String(rsa.Encrypt(data));
         }
 
         /// <summary>
         /// RSA的加密函数 byte[]
         /// </summary>
-        /// <param name="encryptString">需要加密的字节数组</param>
+        /// <param name="data">需要加密的字节数组</param>
         /// <returns>加密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSAEncrypt(this byte[] encryptString)
+        public static string RSAEncrypt(this byte[] data)
         {
-            return RSAEncrypt(encryptString, RsaKey.PublicKey);
+            return RSAEncrypt(data, RsaKey.PublicKey);
         }
 
         #endregion RSA的加密函数
@@ -105,49 +105,49 @@ namespace Masuit.Tools.Security
         /// <summary>
         /// RSA的解密函数  string
         /// </summary>
-        /// <param name="mStrDecryptString">需要解密的字符串</param>
+        /// <param name="value">需要解密的字符串</param>
         /// <param name="privateKey">私钥</param>
         /// <returns>解密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSADecrypt(this string mStrDecryptString, string privateKey)
+        public static string RSADecrypt(this string value, string privateKey)
         {
             var rsa = new RSA(privateKey);
-            return rsa.DecryptOrNull(mStrDecryptString);
+            return rsa.DecryptOrNull(value);
         }
 
         /// <summary>
         /// RSA的解密函数  string
         /// </summary>
-        /// <param name="mStrDecryptString">需要解密的字符串</param>
+        /// <param name="value">需要解密的字符串</param>
         /// <returns>解密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSADecrypt(this string mStrDecryptString)
+        public static string RSADecrypt(this string value)
         {
-            return RSADecrypt(mStrDecryptString, RsaKey.PrivateKey);
+            return RSADecrypt(value, RsaKey.PrivateKey);
         }
 
         /// <summary>
         /// RSA的解密函数  byte
         /// </summary>
-        /// <param name="decryptString">需要解密的字符串</param>
+        /// <param name="data">需要解密的字符串</param>
         /// <param name="privateKey">私钥</param>
         /// <returns>解密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSADecrypt(this byte[] decryptString, string privateKey)
+        public static string RSADecrypt(this byte[] data, string privateKey)
         {
             var rsa = new RSA(privateKey);
-            return new UnicodeEncoding().GetString(rsa.DecryptOrNull(decryptString));
+            return new UnicodeEncoding().GetString(rsa.DecryptOrNull(data));
         }
 
         /// <summary>
         /// RSA的解密函数  byte
         /// </summary>
-        /// <param name="decryptString">需要解密的字符串</param>
+        /// <param name="data">需要解密的字符串</param>
         /// <returns>解密后的内容</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
-        public static string RSADecrypt(this byte[] decryptString)
+        public static string RSADecrypt(this byte[] data)
         {
-            return RSADecrypt(decryptString, RsaKey.PrivateKey);
+            return RSADecrypt(data, RsaKey.PrivateKey);
         }
 
         #endregion RSA的解密函数
@@ -161,26 +161,26 @@ namespace Masuit.Tools.Security
         /// <summary>
         /// 获取Hash描述表
         /// </summary>
-        /// <param name="mStrSource">源数据</param>
+        /// <param name="value">源数据</param>
         /// <returns>Hash描述表</returns>
-        public static byte[] GetHashBytes(this string mStrSource)
+        public static byte[] GetHashBytes(this string value)
         {
             //从字符串中取得Hash描述
             using var md5 = MD5.Create();
-            var buffer = Encoding.UTF8.GetBytes(mStrSource);
+            var buffer = Encoding.UTF8.GetBytes(value);
             return md5.ComputeHash(buffer);
         }
 
         /// <summary>
         /// 获取Hash描述表
         /// </summary>
-        /// <param name="mStrSource">源数据</param>
+        /// <param name="value">源数据</param>
         /// <returns>Hash描述表</returns>
-        public static string GetHashString(this string mStrSource)
+        public static string GetHashString(this string value)
         {
             //从字符串中取得Hash描述
             using var md5 = MD5.Create();
-            var buffer = Encoding.UTF8.GetBytes(mStrSource);
+            var buffer = Encoding.UTF8.GetBytes(value);
             var hashData = md5.ComputeHash(buffer);
             return Convert.ToBase64String(hashData);
         }
@@ -188,25 +188,25 @@ namespace Masuit.Tools.Security
         /// <summary>
         /// 从文件流获取Hash描述表
         /// </summary>
-        /// <param name="objFile">源文件</param>
+        /// <param name="file">源文件</param>
         /// <returns>Hash描述表</returns>
-        public static byte[] GetHashBytes(this FileStream objFile)
+        public static byte[] GetHashBytes(this FileStream file)
         {
             //从文件中取得Hash描述
             using var md5 = MD5.Create();
-            return md5.ComputeHash(objFile);
+            return md5.ComputeHash(file);
         }
 
         /// <summary>
         /// 从文件流获取Hash描述表
         /// </summary>
-        /// <param name="objFile">源文件</param>
+        /// <param name="file">源文件</param>
         /// <returns>Hash描述表</returns>
-        public static string GetHashString(this FileStream objFile)
+        public static string GetHashString(this FileStream file)
         {
             //从文件中取得Hash描述
             using var md5 = MD5.Create();
-            var hashData = md5.ComputeHash(objFile);
+            var hashData = md5.ComputeHash(file);
             return Convert.ToBase64String(hashData);
         }
 
@@ -217,56 +217,56 @@ namespace Masuit.Tools.Security
         /// <summary>
         /// RSA签名
         /// </summary>
-        /// <param name="hashbyteSignature">签名字节数据</param>
+        /// <param name="data">签名字节数据</param>
         /// <param name="privateKey">私钥</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static byte[] SignatureBytes(this byte[] hashbyteSignature, string privateKey)
+        public static byte[] SignatureBytes(this byte[] data, string privateKey)
         {
             var rsa = new RSA(privateKey);
-            return rsa.Sign("MD5", hashbyteSignature);
+            return rsa.Sign("MD5", data);
         }
 
         /// <summary>
         /// RSA签名
         /// </summary>
-        /// <param name="hashbyteSignature">签名字节数据</param>
+        /// <param name="data">签名字节数据</param>
         /// <param name="privateKey">私钥</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static string SignatureString(this byte[] hashbyteSignature, string privateKey)
+        public static string SignatureString(this byte[] data, string privateKey)
         {
-            return Convert.ToBase64String(SignatureBytes(hashbyteSignature, privateKey));
+            return Convert.ToBase64String(SignatureBytes(data, privateKey));
         }
 
         /// <summary>
         /// RSA签名
         /// </summary>
-        /// <param name="mStrHashbyteSignature">签名字符串数据</param>
-        /// <param name="pStrKeyPrivate">私钥</param>
+        /// <param name="value">签名字符串数据</param>
+        /// <param name="privateKey">私钥</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static byte[] SignatureBytes(this string mStrHashbyteSignature, string pStrKeyPrivate)
+        public static byte[] SignatureBytes(this string value, string privateKey)
         {
-            var rsa = new RSA(pStrKeyPrivate);
-            return Encoding.UTF32.GetBytes(rsa.Sign("MD5", mStrHashbyteSignature));
+            var rsa = new RSA(privateKey);
+            return Encoding.UTF32.GetBytes(rsa.Sign("MD5", value));
         }
 
         /// <summary>
         /// RSA签名
         /// </summary>
-        /// <param name="mStrHashbyteSignature">签名字符串数据</param>
-        /// <param name="pStrKeyPrivate">私钥</param>
+        /// <param name="value">签名字符串数据</param>
+        /// <param name="privateKey">私钥</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static string SignatureString(this string mStrHashbyteSignature, string pStrKeyPrivate)
+        public static string SignatureString(this string value, string privateKey)
         {
-            var rsa = new RSA(pStrKeyPrivate);
-            return rsa.Sign("MD5", mStrHashbyteSignature);
+            var rsa = new RSA(privateKey);
+            return rsa.Sign("MD5", value);
         }
 
         #endregion RSA签名
@@ -276,65 +276,65 @@ namespace Masuit.Tools.Security
         /// <summary>
         /// RSA 签名验证
         /// </summary>
-        /// <param name="deformatterData">反格式化字节数据</param>
+        /// <param name="data">反格式化字节数据</param>
         /// <param name="publicKey">公钥</param>
-        /// <param name="hashbyteDeformatter">哈希字节数据</param>
+        /// <param name="sign">哈希字节数据</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static bool SignatureDeformatter(this byte[] deformatterData, string publicKey, byte[] hashbyteDeformatter)
+        public static bool SignatureDeformatter(this byte[] data, string publicKey, byte[] sign)
         {
             var rsa = new RSA(publicKey);
-            return rsa.Verify("MD5", deformatterData, hashbyteDeformatter);
+            return rsa.Verify("MD5", sign, data);
         }
 
         /// <summary>
         /// RSA 签名验证
         /// </summary>
-        /// <param name="deformatterData">反格式化字节数据</param>
+        /// <param name="data">反格式化字节数据</param>
         /// <param name="publicKey">公钥</param>
-        /// <param name="pStrHashbyteDeformatter">哈希字符串数据</param>
+        /// <param name="sign">哈希字符串数据</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static bool SignatureDeformatter(this byte[] deformatterData, string publicKey, string pStrHashbyteDeformatter)
+        public static bool SignatureDeformatter(this byte[] data, string publicKey, string sign)
         {
             var rsa = new RSA(publicKey);
-            return rsa.Verify("MD5", deformatterData, Convert.FromBase64String(pStrHashbyteDeformatter));
+            return rsa.Verify("MD5", Convert.FromBase64String(sign), data);
         }
 
         /// <summary>
         /// RSA 签名验证
         /// </summary>
-        /// <param name="pStrDeformatterData">反格式化字符串数据</param>
+        /// <param name="value">反格式化字符串数据</param>
         /// <param name="publicKey">公钥</param>
-        /// <param name="hashbyteDeformatter">哈希字节数据</param>
+        /// <param name="sign">哈希字节数据</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static bool SignatureDeformatter(this string pStrDeformatterData, string publicKey, byte[] hashbyteDeformatter)
+        public static bool SignatureDeformatter(this string value, string publicKey, byte[] sign)
         {
             var rsa = new RSA(publicKey);
-            return rsa.Verify("MD5", Convert.FromBase64String(pStrDeformatterData), hashbyteDeformatter);
+            return rsa.Verify("MD5", sign, Convert.FromBase64String(value));
         }
 
         /// <summary>
         /// RSA 签名验证
         /// </summary>
-        /// <param name="pStrDeformatterData">格式字符串数据</param>
+        /// <param name="value">格式字符串数据</param>
         /// <param name="publicKey">公钥</param>
-        /// <param name="pStrHashbyteDeformatter">哈希字符串数据</param>
+        /// <param name="sign">哈希字符串数据</param>
         /// <returns>处理结果</returns>
         /// <exception cref="CryptographicException">The cryptographic service provider (CSP) cannot be acquired. </exception>
         /// <exception cref="CryptographicUnexpectedOperationException">The key is null.-or- The hash algorithm is null. </exception>
-        public static bool SignatureDeformatter(this string pStrDeformatterData, string publicKey, string pStrHashbyteDeformatter)
+        public static bool SignatureDeformatter(this string value, string publicKey, string sign)
         {
             var rsa = new RSA(publicKey);
-            return rsa.Verify("MD5", Convert.FromBase64String(pStrDeformatterData), Convert.FromBase64String(pStrHashbyteDeformatter));
+            return rsa.Verify("MD5", sign, value);
         }
 
         #endregion RSA 签名验证
 
         #endregion RSA数字签名
     }
-}
+}

+ 19 - 21
Masuit.Tools.Abstractions/Security/RsaPem.cs

@@ -12,7 +12,7 @@ namespace Masuit.Tools.Security
     /// <summary>
     /// RSA PEM格式密钥对的解析和导出
     /// </summary>
-    public class RsaPem
+    internal class RsaPem
     {
         /// <summary>
         /// modulus 模数n,公钥、私钥都有
@@ -89,7 +89,6 @@ namespace Masuit.Tools.Security
             KeyModulus = modulus;
             KeyExponent = exponent;
             KeyD = d;
-
             ValP = p;
             ValQ = q;
             ValDp = dp;
@@ -207,7 +206,7 @@ namespace Masuit.Tools.Security
         }
 
         /// <summary>
-        /// 由n e d 反推 P Q 
+        /// 由n e d 反推 P Q
         /// </summary>
         private static BigInteger FindFactor(BigInteger e, BigInteger d, BigInteger n)
         {
@@ -252,7 +251,6 @@ namespace Masuit.Tools.Security
             }
         }
 
-
         /// <summary>
         /// 用PEM格式密钥对创建RSA,支持PKCS#1、PKCS#8格式的PEM
         /// 出错将会抛出异常
@@ -260,18 +258,14 @@ namespace Masuit.Tools.Security
         public static RsaPem FromPEM(string pem)
         {
             RsaPem param = new RsaPem();
-
-            var base64 = PemCode.Replace(pem, "");
-            byte[] data = null;
+            var arr = pem.Split('\n');
+            var base64 = arr.Skip(1).Take(arr.Length - 2).Join("\n");
+            byte[] data;
             try
             {
                 data = Convert.FromBase64String(base64);
             }
             catch
-            {
-            }
-
-            if (data == null)
             {
                 throw new Exception("PEM内容无效");
             }
@@ -304,6 +298,7 @@ namespace Masuit.Tools.Security
 
                 throw new Exception("PEM未能提取到数据");
             };
+
             //读取块数据
             Func<byte[]> readBlock = () =>
             {
@@ -323,6 +318,7 @@ namespace Masuit.Tools.Security
                 idx += len;
                 return val;
             };
+
             //比较data从idx位置开始是否是byts内容
             Func<byte[], bool> eq = byts =>
             {
@@ -342,7 +338,6 @@ namespace Masuit.Tools.Security
                 return true;
             };
 
-
             if (pem.Contains("PUBLIC KEY"))
             {
                 //使用公钥
@@ -356,6 +351,7 @@ namespace Masuit.Tools.Security
                     //读取1长度
                     readLen(0x03);
                     idx++; //跳过0x00
+
                     //读取2长度
                     readLen(0x30);
                 }
@@ -388,6 +384,7 @@ namespace Masuit.Tools.Security
                 {
                     //读取1长度
                     readLen(0x04);
+
                     //读取2长度
                     readLen(0x30);
 
@@ -420,19 +417,17 @@ namespace Masuit.Tools.Security
             return param;
         }
 
-        private static readonly Regex PemCode = new Regex(@"--+.+?--+|\s+");
-
         private static readonly byte[] SeqOid = { 0x30, 0x0D, 0x06, 0x09, 0x2A, 0x86, 0x48, 0x86, 0xF7, 0x0D, 0x01, 0x01, 0x01, 0x05, 0x00 };
 
         private static readonly byte[] Ver = { 0x02, 0x01, 0x00 };
 
-
         /// <summary>
         /// 将RSA中的密钥对转换成PEM格式,usePKCS8=false时返回PKCS#1格式,否则返回PKCS#8格式,如果convertToPublic含私钥的RSA将只返回公钥,仅含公钥的RSA不受影响
         /// </summary>
         public string ToPEM(bool convertToPublic, bool usePKCS8)
         {
             var ms = new PooledMemoryStream();
+
             //写入一个长度字节码
             Action<int> writeLenByte = len =>
             {
@@ -452,6 +447,7 @@ namespace Masuit.Tools.Security
                     ms.WriteByte((byte)(len & 0xff));
                 }
             };
+
             //写入一块数据
             Action<byte[]> writeBlock = byts =>
             {
@@ -467,6 +463,7 @@ namespace Masuit.Tools.Security
 
                 ms.Write(byts, 0, byts.Length);
             };
+
             //根据后续内容长度写入长度数据
             Func<int, byte[], byte[]> writeLen = (index, byts) =>
             {
@@ -502,7 +499,6 @@ namespace Masuit.Tools.Security
                 return str.ToString();
             };
 
-
             if (KeyD == null || convertToPublic)
             {
                 //生成公钥
@@ -575,7 +571,6 @@ namespace Masuit.Tools.Security
                 writeBlock(ValDq);
                 writeBlock(ValInverseQ);
 
-
                 //计算空缺的长度
                 var byts = ms.ToArray();
 
@@ -587,7 +582,6 @@ namespace Masuit.Tools.Security
 
                 byts = writeLen(index1, byts);
 
-
                 var flag = " PRIVATE KEY";
                 if (!usePKCS8)
                 {
@@ -598,7 +592,6 @@ namespace Masuit.Tools.Security
             }
         }
 
-
         /// <summary>
         /// 将XML格式密钥转成PEM,支持公钥xml、私钥xml
         /// 出错将会抛出异常
@@ -623,9 +616,11 @@ namespace Masuit.Tools.Security
                     case "Modulus":
                         rtv.KeyModulus = val;
                         break;
+
                     case "Exponent":
                         rtv.KeyExponent = val;
                         break;
+
                     case "D":
                         rtv.KeyD = val;
                         break;
@@ -633,15 +628,19 @@ namespace Masuit.Tools.Security
                     case "P":
                         rtv.ValP = val;
                         break;
+
                     case "Q":
                         rtv.ValQ = val;
                         break;
+
                     case "DP":
                         rtv.ValDp = val;
                         break;
+
                     case "DQ":
                         rtv.ValDq = val;
                         break;
+
                     case "InverseQ":
                         rtv.ValInverseQ = val;
                         break;
@@ -669,7 +668,6 @@ namespace Masuit.Tools.Security
         private static readonly Regex XmlExp = new Regex("\\s*<RSAKeyValue>([<>\\/\\+=\\w\\s]+)</RSAKeyValue>\\s*");
         private static readonly Regex XmlTagExp = new Regex("<(.+?)>\\s*([^<]+?)\\s*</");
 
-
         /// <summary>
         /// 将RSA中的密钥对转换成XML格式
         /// ,如果convertToPublic含私钥的RSA将只返回公钥,仅含公钥的RSA不受影响
@@ -695,4 +693,4 @@ namespace Masuit.Tools.Security
             return str.ToString();
         }
     }
-}
+}

+ 1 - 1
Masuit.Tools.AspNetCore/Masuit.Tools.AspNetCore.csproj

@@ -17,7 +17,7 @@
         <Product>Masuit.Tools.AspNetCore</Product>
         <PackageId>Masuit.Tools.AspNetCore</PackageId>
         <LangVersion>latest</LangVersion>
-        <Version>1.2</Version>
+        <Version>1.2.0.1</Version>
         <RepositoryType></RepositoryType>
         <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
         <FileVersion>1.1.9</FileVersion>

+ 1 - 1
Masuit.Tools.Core/Masuit.Tools.Core.csproj

@@ -6,7 +6,7 @@
 官网教程:https://ldqk.org/55
 github:https://github.com/ldqk/Masuit.Tools
         </Description>
-        <Version>2.6</Version>
+        <Version>2.6.0.1</Version>
         <Copyright>Copyright © 懒得勤快</Copyright>
         <PackageProjectUrl>https://github.com/ldqk/Masuit.Tools</PackageProjectUrl>
         <PackageTags>Masuit.Tools,工具库,Utility,Crypt,Extensions</PackageTags>

+ 2 - 2
Masuit.Tools.Excel/Masuit.Tools.Excel.csproj

@@ -3,7 +3,7 @@
         <TargetFramework>netstandard2.0</TargetFramework>
         <LangVersion>latest</LangVersion>
         <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
-        <Version>1.2.5.4</Version>
+        <Version>1.2.5.5</Version>
         <Authors>懒得勤快</Authors>
         <Description>Masuit.Tools.Excel导出库,支持一些简单数据的导出,支持图片列</Description>
         <Copyright>懒得勤快</Copyright>
@@ -38,7 +38,7 @@
       </None>
     </ItemGroup>
     <ItemGroup>
-        <PackageReference Include="EPPlus" Version="6.2.1" />
+        <PackageReference Include="EPPlus" Version="6.2.2" />
         <PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
     </ItemGroup>
     <ItemGroup>

+ 1 - 1
Masuit.Tools.Net45/package.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Masuit.Tools.Net45</id>
-    <version>2.6</version>
+    <version>2.6.0.1</version>
     <title>Masuit.Tools</title>
     <authors>懒得勤快</authors>
     <owners>masuit.com</owners>

+ 1 - 1
Masuit.Tools/package.nuspec

@@ -2,7 +2,7 @@
 <package>
   <metadata>
     <id>Masuit.Tools.Net</id>
-    <version>2.6</version>
+    <version>2.6.0.1</version>
     <title>Masuit.Tools</title>
     <authors>懒得勤快</authors>
     <owners>masuit.com</owners>

+ 14 - 13
NetCoreTest/Program.cs

@@ -1,19 +1,20 @@
 using Masuit.Tools.AspNetCore.ModelBinder;
-using Masuit.Tools.Files;
-using Masuit.Tools.Media;
-using Masuit.Tools.Reflection;
 
-var attributes = MyEnum.A.GetTypedEnumDescriptions();
-Console.ReadKey();
-MyStruct<object>? a = null;
+var builder = WebApplication.CreateBuilder(args);
+builder.Services.AddControllers(options => options.ModelBinderProviders.InsertBodyOrDefaultBinding());
+builder.Services.AddEndpointsApiExplorer();
+builder.Services.AddSwaggerGen();
 
-public enum MyEnum
-{
-    [EnumDescription("A", "a")]
-    A
-}
+var app = builder.Build();
 
-internal struct MyStruct<T>
+if (app.Environment.IsDevelopment())
 {
-    public T Value { get; set; }
+    app.UseSwagger();
+    app.UseSwaggerUI();
 }
+
+app.UseAuthorization();
+
+app.MapControllers();
+
+app.Run();

+ 13 - 1
Test/Masuit.Tools.Abstractions.Test/Security/RsaCryptTest.cs

@@ -9,6 +9,7 @@ namespace Masuit.Tools.Abstractions.Test.Security
         public class RsaCryptTestEntity
         {
             public string Name { get; set; }
+
             public DateTime SdTime { get; set; }
         }
 
@@ -33,5 +34,16 @@ namespace Masuit.Tools.Abstractions.Test.Security
             }
             .ToJsonString());
         }
+
+        [Fact]
+        public void Ç©ÃûÑéÖ¤()
+        {
+            RsaKey rsaKey = RsaCrypt.GenerateRsaKeys();
+            string data = "Hello World!".Base64Encrypt();
+            string sign = data.SignatureString(rsaKey.PrivateKey);
+
+            // ÑéÖ¤½á¹ûΪFalse
+            Assert.True(data.SignatureDeformatter(rsaKey.PublicKey, sign));
+        }
     }
-}
+}

+ 1 - 1
Test/Masuit.Tools.Core.Test/Masuit.Tools.Core.Test.csproj

@@ -9,7 +9,7 @@
   </PropertyGroup>
 
   <ItemGroup>
-    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.4" />
+    <PackageReference Include="Microsoft.AspNetCore.TestHost" Version="7.0.5" />
     <PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
     <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
     <PackageReference Include="xunit" Version="2.4.2" />