From 845bb16392e6b47ec31147d0e7c6ddc39537f2e7 Mon Sep 17 00:00:00 2001
From: hxb <hxb@hdlchina.com.cn>
Date: 星期三, 16 二月 2022 13:05:21 +0800
Subject: [PATCH] 解密有问题后不往上层发
---
HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java | 40 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java
index 3634ce4..f3b663b 100644
--- a/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java
+++ b/HDLSDK/hdl-connect/src/main/java/com/hdl/sdk/connect/bean/LinkRequest.java
@@ -4,12 +4,18 @@
import androidx.annotation.NonNull;
+import com.hdl.sdk.common.utils.LogUtils;
+import com.hdl.sdk.connect.config.HDLLinkConfig;
+import com.hdl.sdk.common.utils.ByteUtils;
+import com.hdl.sdk.connect.utils.AesUtil;
+
/**
* Created by Tong on 2021/9/29.
*/
public class LinkRequest {
private String topic;
private String data;
+
private int length;
public LinkRequest() {
@@ -35,7 +41,7 @@
public void setData(String data) {
this.data = data;
if (!TextUtils.isEmpty(data)) {
- setLength(data.length());
+ setLength(getBytesLength(data));
} else {
setLength(0);
}
@@ -61,4 +67,36 @@
"\r\n\r\n" +
getData();
}
+
+
+ private int getBytesLength(String str) {
+ return ByteUtils.stringToBytes(str).length;
+ }
+
+
+ /**
+ * 鑾峰彇鍙戦�佹暟鎹産yte
+ *
+ * @return
+ */
+ public byte[] getSendBytes() {
+ try {
+ //鍒ゆ柇鏄惁闇�瑕佸姞瀵�
+ if (HDLLinkConfig.getInstance().ifNeedEncrypt(topic)) {
+ //闇�瑕佸姞瀵�
+ byte[] dataBytes = AesUtil.aesEncrypt(ByteUtils.stringToBytes(data), HDLLinkConfig.getInstance().getLocalSecret());
+ String headString = "Topic:" + getTopic() + "\r\n" + "Length:" + dataBytes.length + "\r\n" + "\r\n";
+ byte[] headBytes = headString.getBytes("utf-8");
+ byte[] sendBytes = ByteUtils.concatBytes(headBytes, dataBytes);
+ LogUtils.i(headString + "\r\n" + data);
+ return sendBytes;
+
+ } else {
+ return this.toString().getBytes("utf-8");
+ }
+
+ } catch (Exception e) {
+ return new byte[]{};
+ }
+ }
}
--
Gitblit v1.8.0