From 454ac814944cf956ff02b84b70ba2ec68e5e5ea1 Mon Sep 17 00:00:00 2001 From: JLChen <551775569@qq.com> Date: 星期三, 15 一月 2020 19:38:47 +0800 Subject: [PATCH] 2020-01-15 1.优化MQTT连接。 2.增加本地通信加密。 --- Crabtree/SmartHome/HDL/Operation/Packet.cs | 27 ++++++++++++++------------- 1 files changed, 14 insertions(+), 13 deletions(-) diff --git a/Crabtree/SmartHome/HDL/Operation/Packet.cs b/Crabtree/SmartHome/HDL/Operation/Packet.cs index ded4f36..923327a 100644 --- a/Crabtree/SmartHome/HDL/Operation/Packet.cs +++ b/Crabtree/SmartHome/HDL/Operation/Packet.cs @@ -59,9 +59,6 @@ { //鍔犲瘑妫�娴� EncryptionDetection (); - - - //瀵逛簬鎿嶄綔鏁版嵁搴撶殑鏃堕棿姣旇緝闀跨殑锛屽彲浠ュ垱寤哄彟涓�涓嚎绋嬪鐞� if (!"HDLMIRACLE".Equals (System.Text.Encoding.ASCII.GetString (Bytes, 4, 10))) { return; @@ -69,7 +66,6 @@ byte subnetID = this.Bytes [17]; //婧愬瓙缃戝彿 byte deviceID = this.Bytes [18]; //婧愯澶囧彿 - //婧愯澶囩被鍨� int deviceType = this.Bytes [19] * 256 + this.Bytes [20]; @@ -130,21 +126,26 @@ if (IsLocal) {//鏈湴閫氳 if (UserConfig.Instance.IsLocalEncrypt) { - if ("Passord error" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 13))) { - //缃戝叧杩斿洖锛屽姞瀵嗗瘑鐮乲ey涓嶅 - - return; + if (Bytes.Length == 28) { + var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 14); + if ("Password error" == mes) { + //缃戝叧杩斿洖锛屽姞瀵嗗瘑鐮乲ey涓嶅 + UserConfig.Instance.EncryptedPasswordCorrect = false; + return; + } } - var messageGet = Shared.Securitys.EncryptionService.AesEncryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey); + var messageGet = Shared.Securitys.EncryptionService.AesDecryptPayload (Bytes, UserConfig.Instance.LocalEncryptKey); Bytes = messageGet; } else { - if ("Locked" == (System.Text.Encoding.ASCII.GetString (Bytes, 14, 6))) { - //缃戝叧宸插姞瀵嗭紝鑷姩鍒囨崲涓哄姞瀵� - UserConfig.Instance.IsLocalEncrypt = true; + if (Bytes.Length == 20) { + var mes = System.Text.Encoding.ASCII.GetString (Bytes, 14, 6); + if ("Locked" == mes) { + //缃戝叧宸插姞瀵嗭紝鑷姩鍒囨崲涓哄姞瀵� + UserConfig.Instance.IsLocalEncrypt = true; + } } - } } -- Gitblit v1.8.0