From b2ad000e07e1c87d3561b5aa94fdc88c779872f0 Mon Sep 17 00:00:00 2001
From: dengjunjie <dengjunjie@hnkhzn.com>
Date: 星期二, 18 二月 2025 22:34:54 +0800
Subject: [PATCH] 1

---
 项目代码/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/SecurityEncDecryptHelper.cs |   93 ++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 93 insertions(+), 0 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/SecurityEncDecryptHelper.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/SecurityEncDecryptHelper.cs"
new file mode 100644
index 0000000..5c8c45d
--- /dev/null
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WMS/WIDESEA_WMSServer/WIDESEA_Core/Helper/SecurityEncDecryptHelper.cs"
@@ -0,0 +1,93 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading.Tasks;
+using WIDESEA_Core.Const;
+using WIDESEA_Core.DB;
+
+namespace WIDESEA_Core.Helper
+{
+    public static class SecurityEncDecryptHelper
+    {
+        private static byte[] Keys = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F };
+        /// <summary> 
+        /// DES鍔犲瘑瀛楃涓� 
+        /// </summary> 
+        /// <param name="encryptString">寰呭姞瀵嗙殑瀛楃涓�</param> 
+        /// <param name="encryptKey">鍔犲瘑瀵嗛挜,瑕佹眰涓�16浣�</param> 
+        /// <returns>鍔犲瘑鎴愬姛杩斿洖鍔犲瘑鍚庣殑瀛楃涓诧紝澶辫触杩斿洖婧愪覆</returns> 
+
+        public static string EncryptDES(this string encryptString, string encryptKey)
+        {
+            try
+            {
+                byte[] rgbKey = Encoding.UTF8.GetBytes(encryptKey.Substring(0, 16));
+                byte[] rgbIV = Keys;
+                byte[] inputByteArray = Encoding.UTF8.GetBytes(encryptString);
+
+                using (var DCSP = Aes.Create())
+                {
+                    using (MemoryStream mStream = new MemoryStream())
+                    {
+                        using (CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateEncryptor(rgbKey, rgbIV), CryptoStreamMode.Write))
+                        {
+                            cStream.Write(inputByteArray, 0, inputByteArray.Length);
+                            cStream.FlushFinalBlock();
+                            return Convert.ToBase64String(mStream.ToArray()).Replace('+', '_').Replace('/', '~');
+                        }
+                    }
+                }
+            }
+            catch (Exception ex)
+            {
+                throw new Exception("瀵嗙爜鍔犲瘑寮傚父" + ex.Message);
+            }
+
+        }
+
+        /// <summary> 
+        /// DES瑙e瘑瀛楃涓� 
+        /// </summary> 
+        /// <param name="decryptString">寰呰В瀵嗙殑瀛楃涓�</param> 
+        /// <param name="decryptKey">瑙e瘑瀵嗛挜,瑕佹眰涓�16浣�,鍜屽姞瀵嗗瘑閽ョ浉鍚�</param> 
+        /// <returns>瑙e瘑鎴愬姛杩斿洖瑙e瘑鍚庣殑瀛楃涓诧紝澶辫触杩旀簮涓�</returns> 
+
+        public static string DecryptDES(this string decryptString, string decryptKey)
+        {
+            if (decryptKey == AppSecret.DB && !AppSettings.app(MainDb.ConnectionStringsEncryption).ObjToBool())
+                return decryptString;
+
+            byte[] rgbKey = Encoding.UTF8.GetBytes(decryptKey.Substring(0, 16));
+            byte[] rgbIV = Keys;
+            byte[] inputByteArray = Convert.FromBase64String(decryptString.Replace('_', '+').Replace('~', '/'));
+            using (var DCSP = Aes.Create())
+            {
+                using (MemoryStream mStream = new MemoryStream())
+                {
+                    using (CryptoStream cStream = new CryptoStream(mStream, DCSP.CreateDecryptor(rgbKey, rgbIV), CryptoStreamMode.Write))
+                    {
+                        byte[] inputByteArrays = new byte[inputByteArray.Length];
+                        cStream.Write(inputByteArray, 0, inputByteArray.Length);
+                        cStream.FlushFinalBlock();
+                        return Encoding.UTF8.GetString(mStream.ToArray());
+                    }
+                }
+            }
+        }
+        public static bool TryDecryptDES(this string decryptString, string decryptKey, out string result)
+        {
+            result = "";
+            try
+            {
+                result = DecryptDES(decryptString, decryptKey);
+                return true;
+            }
+            catch
+            {
+                return false;
+            }
+        }
+    }
+}

--
Gitblit v1.9.3