From 89b9d5306b6c14231ba3e8d4997fa643c399bf68 Mon Sep 17 00:00:00 2001 From: shanji <18996038927@163.com> Date: Tue, 30 Jan 2024 12:24:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BD=91=E9=A1=B5=E6=8A=93=E7=BB=8F=E8=90=A5?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BBWYB.PurchaserCapture.csproj | 6 +- BBWYB.PurchaserCapture/EncryptionExtension.cs | 83 ++++ BBWYB.PurchaserCapture/MainWindow.xaml | 9 +- BBWYB.PurchaserCapture/MainWindow.xaml.cs | 110 +++++- BBWYB.PurchaserCapture/Model/Db/Purchaser.cs | 113 ++++++ .../Model/Db/Purchaseschemeproduct.cs | 53 +++ BBWYB.PurchaserCapture/Model/Enums.cs | 359 ++++++++++++++++++ 7 files changed, 721 insertions(+), 12 deletions(-) create mode 100644 BBWYB.PurchaserCapture/EncryptionExtension.cs create mode 100644 BBWYB.PurchaserCapture/Model/Db/Purchaser.cs create mode 100644 BBWYB.PurchaserCapture/Model/Db/Purchaseschemeproduct.cs create mode 100644 BBWYB.PurchaserCapture/Model/Enums.cs diff --git a/BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj b/BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj index a668083..fc64378 100644 --- a/BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj +++ b/BBWYB.PurchaserCapture/BBWYB.PurchaserCapture.csproj @@ -1,7 +1,7 @@  - WinExe + Exe net6.0-windows enable enable @@ -9,9 +9,13 @@ + + + + diff --git a/BBWYB.PurchaserCapture/EncryptionExtension.cs b/BBWYB.PurchaserCapture/EncryptionExtension.cs new file mode 100644 index 0000000..517892e --- /dev/null +++ b/BBWYB.PurchaserCapture/EncryptionExtension.cs @@ -0,0 +1,83 @@ +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace BBWYB.Common.Extensions +{ + public static class EncryptionExtension + { + + public static string Md5Encrypt(this string originStr) + { + using (var md5 = MD5.Create()) + { + return string.Join(string.Empty, md5.ComputeHash(Encoding.UTF8.GetBytes(originStr)).Select(x => x.ToString("x2"))); + } + } + + //AES加密 传入,要加密的串和, 解密key + public static string AESEncrypt(this string input) + { + var key = "dataplatform2019"; + var ivStr = "1012132405963708"; + + var encryptKey = Encoding.UTF8.GetBytes(key); + var iv = Encoding.UTF8.GetBytes(ivStr); //偏移量,最小为16 + using (var aesAlg = Aes.Create()) + { + using (var encryptor = aesAlg.CreateEncryptor(encryptKey, iv)) + { + using (var msEncrypt = new MemoryStream()) + { + using (var csEncrypt = new CryptoStream(msEncrypt, encryptor, + CryptoStreamMode.Write)) + + using (var swEncrypt = new StreamWriter(csEncrypt)) + { + swEncrypt.Write(input); + } + var decryptedContent = msEncrypt.ToArray(); + + return Convert.ToBase64String(decryptedContent); + } + } + } + } + + public static string AESDecrypt(this string cipherText) + { + var fullCipher = Convert.FromBase64String(cipherText); + + var ivStr = "1012132405963708"; + var key = "dataplatform2019"; + + var iv = Encoding.UTF8.GetBytes(ivStr); + var decryptKey = Encoding.UTF8.GetBytes(key); + + using (var aesAlg = Aes.Create()) + { + using (var decryptor = aesAlg.CreateDecryptor(decryptKey, iv)) + { + string result; + using (var msDecrypt = new MemoryStream(fullCipher)) + { + using (var csDecrypt = new CryptoStream(msDecrypt, decryptor, CryptoStreamMode.Read)) + { + using (var srDecrypt = new StreamReader(csDecrypt)) + { + result = srDecrypt.ReadToEnd(); + } + } + } + + return result; + } + } + } + + public static string Base64Encrypt(this string originStr) + { + return Convert.ToBase64String(Encoding.UTF8.GetBytes(originStr)); + } + } +} diff --git a/BBWYB.PurchaserCapture/MainWindow.xaml b/BBWYB.PurchaserCapture/MainWindow.xaml index a08f3b2..afee5af 100644 --- a/BBWYB.PurchaserCapture/MainWindow.xaml +++ b/BBWYB.PurchaserCapture/MainWindow.xaml @@ -6,7 +6,12 @@ xmlns:local="clr-namespace:BBWYB.PurchaserCapture" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> - - + + + + + + +