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"> - - + + + + + + +