Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
N
nlt-pufa-interface
Overview
Overview
Details
Activity
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
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
邓梁
nlt-pufa-interface
Commits
b8fd70df
Commit
b8fd70df
authored
Sep 30, 2024
by
dliangx
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
去掉变量
parent
c92d6aa7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
15 deletions
+8
-15
model/http_body.go
+8
-15
No files found.
model/http_body.go
View file @
b8fd70df
package
model
import
(
"crypto"
"crypto/rand"
"encoding/base64"
"encoding/hex"
...
...
@@ -61,6 +62,7 @@ func EncryptAndSign[T any](resp HttpBodyResp[T]) (CryptHttpBodyResp, error) {
log
.
Println
(
err
.
Error
())
return
cresp
,
err
}
ciphertext
,
err
:=
sm2
.
Encrypt
(
publicKey
,
body
,
rand
.
Reader
,
sm2
.
C1C2C3
)
if
err
!=
nil
{
log
.
Println
(
err
)
...
...
@@ -69,23 +71,14 @@ func EncryptAndSign[T any](resp HttpBodyResp[T]) (CryptHttpBodyResp, error) {
cresp
.
Response
.
Head
=
resp
.
Head
cresp
.
Response
.
Response
=
base64
.
RawStdEncoding
.
EncodeToString
(
ciphertext
)
jsonResp
,
err
:=
json
.
Marshal
(
resp
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
uid
:=
[]
byte
(
"tk"
)
r
,
s
,
err
:=
sm2
.
Sm2Sign
(
privateKeyBytes
,
jsonResp
,
uid
,
rand
.
Reader
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
signature
,
err
:=
sm2
.
SignDigitToSignData
(
r
,
s
)
jsonResp
,
err
:=
json
.
Marshal
(
cresp
.
Response
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
cresp
,
err
}
signature
,
err
:=
privateKeyBytes
.
Sign
(
rand
.
Reader
,
jsonResp
,
crypto
.
BLAKE2b_256
)
cresp
.
Signature
=
base64
.
RawStdEncoding
.
EncodeToString
(
signature
)
return
cresp
,
err
}
...
...
@@ -106,13 +99,13 @@ func VerifyAndDecrypt[T any](creq CryptHttpBodyReq) (HttpBodyReq[T], error) {
log
.
Println
(
err
)
return
req
,
err
}
r
,
s
,
err
:=
sm2
.
SignDataToSignDigit
(
signature
)
jsonReq
,
err
:=
json
.
Marshal
(
creq
.
Request
)
if
err
!=
nil
{
log
.
Println
(
err
)
return
req
,
err
}
uid
:=
[]
byte
(
"tk"
)
if
sm2
.
Sm2Verify
(
publicKey
,
signature
,
uid
,
r
,
s
)
{
if
publicKey
.
Verify
(
jsonReq
,
signature
)
{
body
,
err
:=
base64
.
RawStdEncoding
.
DecodeString
(
creq
.
Request
.
Request
)
if
err
!=
nil
{
log
.
Println
(
err
)
...
...
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