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
8e6d8012
Commit
8e6d8012
authored
Nov 14, 2022
by
AfirSraftGarrier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
格式并加些打印
parent
dc3dc14b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
19 deletions
+37
-19
DeviceControllerTest.java
.../iot/sixiang/license/controller/DeviceControllerTest.java
+36
-18
SM4.java
license/src/test/java/iot/sixiang/license/util/sm4/SM4.java
+1
-1
No files found.
license/src/test/java/iot/sixiang/license/controller/DeviceControllerTest.java
View file @
8e6d8012
...
...
@@ -3,9 +3,13 @@ package iot.sixiang.license.controller;
import
com.alibaba.fastjson2.JSON
;
import
iot.sixiang.license.object.data.AuthData
;
import
iot.sixiang.license.util.HmacUtil
;
import
iot.sixiang.license.util.sm4.SM4Utils
;
import
iot.sixiang.license.util.sm4.SM4
;
import
iot.sixiang.license.util.sm4.SM4Context
;
import
org.junit.jupiter.api.Test
;
import
java.io.ByteArrayInputStream
;
import
java.io.ByteArrayOutputStream
;
/**
* Created by M=54G
* Date 11/11/22 9:54 AM
...
...
@@ -19,7 +23,6 @@ public class DeviceControllerTest {
String
sn
=
"ERE54S619LNYMPKVN9"
;
String
appKey
=
"110801"
;
//showSendData(appId, sn, appKey);
goDo
(
"hellogo"
);
}
private
void
showSendData
(
String
appId
,
String
sn
,
String
appKey
)
{
...
...
@@ -55,22 +58,37 @@ public class DeviceControllerTest {
System
.
out
.
println
(
bytes2Hex
(
allBytes
));
}
private
void
goDo
(
String
string
)
{
SM4Utils
sm4
=
new
SM4Utils
();
String
secret
=
"9ec55e355f1e829e"
;
// 设置 密钥 16长度的字符
sm4
.
setSecretKey
(
secret
);
// 设置 向量 16长度的字符
// sm4.setIv("ee6855f0ea29e9e2");
// 设置待加密的文本
String
plainText
=
string
;
// 声明密钥和向量是否是32长度的十六进制的字符串,如果true则需要设置密钥向量都是十六进制的32长度字符串。Util.byteToHex("b7b3gSMFWd9a67i1".getBytes())
// sm4.setHexString(false);
// 进行加密
String
encryptString
=
sm4
.
encryptData_ECB
(
plainText
);
System
.
out
.
println
(
"原文:"
+
string
);
System
.
out
.
println
(
"密文: "
+
encryptString
);
public
byte
[]
encryptData_ECB
(
String
string
,
byte
[]
keyBytes
)
{
try
{
SM4Context
ctx
=
new
SM4Context
();
ctx
.
mode
=
SM4
.
SM4_ENCRYPT
;
SM4
sm4
=
new
SM4
();
sm4
.
sm4_setkey_enc
(
ctx
,
keyBytes
);
byte
[]
encrypted
=
sm4_crypt_ecb
(
sm4
,
ctx
,
string
.
getBytes
(
"UTF-8"
));
return
encrypted
;
}
catch
(
Exception
e
)
{
e
.
printStackTrace
();
return
null
;
}
}
public
byte
[]
sm4_crypt_ecb
(
SM4
sm4
,
SM4Context
ctx
,
byte
[]
input
)
throws
Exception
{
int
length
=
input
.
length
;
ByteArrayInputStream
bins
=
new
ByteArrayInputStream
(
input
);
ByteArrayOutputStream
bous
=
new
ByteArrayOutputStream
();
for
(;
length
>
0
;
length
-=
16
)
{
byte
[]
in
=
new
byte
[
16
];
byte
[]
out
=
new
byte
[
16
];
bins
.
read
(
in
);
sm4
.
sm4_one_round
(
ctx
.
sk
,
in
,
out
);
bous
.
write
(
out
);
}
byte
[]
output
=
bous
.
toByteArray
();
bins
.
close
();
bous
.
close
();
return
output
;
}
@Test
...
...
license/src/test/java/iot/sixiang/license/util/sm4/SM4.java
View file @
8e6d8012
...
...
@@ -143,7 +143,7 @@ public class SM4 {
}
}
p
rivate
void
sm4_one_round
(
long
[]
sk
,
byte
[]
input
,
byte
[]
output
)
{
p
ublic
void
sm4_one_round
(
long
[]
sk
,
byte
[]
input
,
byte
[]
output
)
{
int
i
=
0
;
long
[]
ulbuf
=
new
long
[
36
];
ulbuf
[
0
]
=
GET_ULONG_BE
(
input
,
0
);
...
...
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