Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
ioc_sixiang_license
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
zengtianlai3
ioc_sixiang_license
Commits
d7049cf1
Commit
d7049cf1
authored
Nov 14, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式并加些打印
parent
8e6d8012
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
6 deletions
+25
-6
DeviceControllerTest.java
.../iot/sixiang/license/controller/DeviceControllerTest.java
+25
-6
No files found.
license/src/test/java/iot/sixiang/license/controller/DeviceControllerTest.java
View file @
d7049cf1
...
...
@@ -9,6 +9,7 @@ import org.junit.jupiter.api.Test;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
import
java.util.Random
;
/**
* Created by M=54G
...
...
@@ -22,27 +23,45 @@ public class DeviceControllerTest {
String
appId
=
"ebsh71dp5t1ck948l5"
;
String
sn
=
"ERE54S619LNYMPKVN9"
;
String
appKey
=
"110801"
;
//showSendData(appId, sn, appKey);
//byte[] baseKeyBytes = "nAOq38p4bGQyF4FG".getBytes();
//System.out.println(baseKeyBytes.length);
showSendData
(
appId
,
sn
,
appKey
);
}
private
void
showSendData
(
String
appId
,
String
sn
,
String
appKey
)
{
byte
[]
stxBytes
=
{(
byte
)
0x55
,
(
byte
)
0xaa
};
// 这部分生成内容
// 用于SM4
byte
[]
randomBytes
=
new
byte
[
16
];
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
<
randomBytes
.
length
;
i
++)
{
randomBytes
[
i
]
=
(
byte
)
(
random
.
nextInt
());
}
byte
[]
sm4KeyBytes
=
new
byte
[
16
];
byte
[]
baseKeyBytes
=
"nAOq38p4bGQyF4FG"
.
getBytes
();
for
(
int
i
=
0
;
i
<
randomBytes
.
length
;
i
++)
{
sm4KeyBytes
[
i
]
=
(
byte
)
(
randomBytes
[
i
]
^
baseKeyBytes
[
i
]);
}
String
string
=
"app_id="
+
appId
+
"&sn="
+
sn
;
String
sign
=
HmacUtil
.
encrypt
(
string
,
appKey
,
HmacUtil
.
HMAC_SHA1
);
// 组装
AuthData
authData
=
new
AuthData
();
authData
.
setAppId
(
appId
);
authData
.
setSn
(
sn
);
authData
.
setSign
(
sign
);
byte
[]
dataBytes
=
JSON
.
toJSONString
(
authData
).
getBytes
();
byte
[]
dataBytes
=
encryptData_ECB
(
JSON
.
toJSONString
(
authData
),
sm4KeyBytes
);
dataBytes
=
byteMerger
(
randomBytes
,
dataBytes
);
int
length
=
dataBytes
.
length
+
stxBytes
.
length
;
byte
[]
lenBytes
=
{(
byte
)
(
0xff
&
length
),
(
byte
)
(
0xff
&
(
length
>>
8
)
)};
byte
[]
lenBytes
=
{(
byte
)
length
,
(
byte
)
(
length
>>
8
)};
// 这部分是命令
byte
cmdByte
=
(
byte
)
0x01
;
byte
ackByte
=
(
byte
)
0x00
;
// 结束符
byte
endByte
=
(
byte
)
0x00
;
// 加密最后字段
...
...
@@ -117,7 +136,7 @@ public class DeviceControllerTest {
byte
[]
dataBytes
=
JSON
.
toJSONString
(
authData
).
getBytes
();
int
length
=
dataBytes
.
length
+
stxBytes
.
length
;
byte
[]
lenBytes
=
{(
byte
)
(
0xff
&
length
),
(
byte
)
(
0xff
&
(
length
>>
8
)
)};
byte
[]
lenBytes
=
{(
byte
)
length
,
(
byte
)
(
length
>>
8
)};
byte
cmdByte
=
(
byte
)
0x01
;
byte
ackByte
=
(
byte
)
0x00
;
...
...
@@ -187,7 +206,7 @@ public class DeviceControllerTest {
byte
[]
baKeyword
=
new
byte
[
s
.
length
()
/
2
];
for
(
int
i
=
0
;
i
<
baKeyword
.
length
;
i
++)
{
try
{
baKeyword
[
i
]
=
(
byte
)
(
0xff
&
Integer
.
parseInt
(
s
.
substring
(
i
*
2
,
i
*
2
+
2
),
16
)
);
baKeyword
[
i
]
=
(
byte
)
Integer
.
parseInt
(
s
.
substring
(
i
*
2
,
i
*
2
+
2
),
16
);
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment