From f71e74b5f0d2716fbf05da016cdaa18d64e09f80 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 31 十二月 2020 17:01:18 +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