From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/Shared/Phone/ZigBee/Common/EncryptionService.cs | 64 ++++++++++++++++++++++++++++++++ 1 files changed, 64 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/ZigBee/Common/EncryptionService.cs b/ZigbeeApp/Shared/Phone/ZigBee/Common/EncryptionService.cs new file mode 100755 index 0000000..7ab2392 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/ZigBee/Common/EncryptionService.cs @@ -0,0 +1,64 @@ +锘縰sing System; +using System.IO; +using System.Security.Cryptography; +using System.Text; + +namespace ZigBee.Common +{ + public static class EncryptionService + { + /// <summary> + /// 浣跨敤DES杩涜鍔犲瘑 + /// </summary> + /// <param name="pToEncrypt"></param> + /// <param name="key"></param> + /// <returns></returns> + public static string DESEncrypt(string pToEncrypt, string key) + { + using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) + { + byte[] inputByteArray = Encoding.UTF8.GetBytes(pToEncrypt); + des.Key = ASCIIEncoding.ASCII.GetBytes(key); + des.IV = ASCIIEncoding.ASCII.GetBytes(key); + + MemoryStream ms = new MemoryStream(); + + using (CryptoStream cs = new CryptoStream(ms, des.CreateEncryptor(), CryptoStreamMode.Write)) + { + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + cs.Close(); + } + string str = Convert.ToBase64String(ms.ToArray()); + ms.Close(); + return str; + } + } + /// <summary> + /// 浣跨敤DES杩涜瑙e瘑 + /// </summary> + /// <param name="pToDecrypt"></param> + /// <param name="key"></param> + /// <returns></returns> + public static string DESDecrypt(string pToDecrypt, string key) + { + byte[] inputByteArray = Convert.FromBase64String(pToDecrypt); + using (DESCryptoServiceProvider des = new DESCryptoServiceProvider()) + { + des.Key = ASCIIEncoding.ASCII.GetBytes(key); + des.IV = ASCIIEncoding.ASCII.GetBytes(key); + + MemoryStream ms = new MemoryStream(); + using (CryptoStream cs = new CryptoStream(ms, des.CreateDecryptor(), CryptoStreamMode.Write)) + { + cs.Write(inputByteArray, 0, inputByteArray.Length); + cs.FlushFinalBlock(); + cs.Close(); + } + string str = Encoding.UTF8.GetString(ms.ToArray()); + ms.Close(); + return str; + } + } + } +} -- Gitblit v1.8.0