Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
bwallet
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Go
bwallet
Commits
3e58950d
Commit
3e58950d
authored
Dec 15, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aes encrypt
parent
43c1bc85
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
7 deletions
+22
-7
aes.go
middleware/sign/aes/aes.go
+19
-6
router.go
routers/router.go
+3
-1
No files found.
middleware/sign/aes/aes.go
View file @
3e58950d
...
...
@@ -5,8 +5,10 @@ import (
"bwallet/pkg/errno"
"bwallet/pkg/handler"
"bwallet/pkg/util"
"errors"
"fmt"
"github.com/gin-gonic/gin"
"github.com/xinliangnote/go-util/aes"
"net/url"
"sort"
"strconv"
...
...
@@ -49,7 +51,7 @@ func verifySign(c *gin.Context) (map[string]string, error) {
// 验证来源
value
,
ok
:=
config
.
ApiAuthConfig
[
ak
]
if
ok
{
AppSecret
=
value
[
"
md5
"
]
AppSecret
=
value
[
"
aes
"
]
}
else
{
return
nil
,
errno
.
ErrAk
}
...
...
@@ -57,9 +59,14 @@ func verifySign(c *gin.Context) (map[string]string, error) {
if
debug
==
"1"
{
currentUnix
:=
util
.
GetCurrentUnix
()
req
.
Set
(
"ts"
,
strconv
.
FormatInt
(
currentUnix
,
10
))
sn
,
err
:=
createSign
(
req
)
if
err
!=
nil
{
return
nil
,
errno
.
ErrSn
}
res
:=
map
[
string
]
string
{
"ts"
:
strconv
.
FormatInt
(
currentUnix
,
10
),
"sn"
:
createSign
(
req
)
,
"sn"
:
sn
,
}
return
res
,
nil
}
...
...
@@ -73,17 +80,23 @@ func verifySign(c *gin.Context) (map[string]string, error) {
}
// 验证签名
if
sn
==
""
||
sn
!=
createSign
(
req
)
{
if
sn
==
""
{
return
nil
,
errno
.
ErrSn
}
decryptStr
,
decryptErr
:=
aes
.
Decrypt
(
sn
,
[]
byte
(
AppSecret
),
AppSecret
)
if
decryptErr
!=
nil
{
return
nil
,
errors
.
New
(
decryptErr
.
Error
())
}
if
decryptStr
!=
createEncryptStr
(
req
)
{
return
nil
,
errno
.
ErrSn
}
return
nil
,
nil
}
// 创建签名
func
createSign
(
params
url
.
Values
)
string
{
// 自定义 MD5 组合
return
util
.
EncodeMD5
(
AppSecret
+
createEncryptStr
(
params
)
+
AppSecret
)
func
createSign
(
params
url
.
Values
)
(
string
,
error
)
{
return
aes
.
Encrypt
(
createEncryptStr
(
params
),
[]
byte
(
AppSecret
),
AppSecret
)
}
func
createEncryptStr
(
params
url
.
Values
)
string
{
...
...
routers/router.go
View file @
3e58950d
...
...
@@ -28,6 +28,8 @@ func InitRouter() *gin.Engine {
//r.POST("/upload", api.UploadImage)
client
:=
r
.
Group
(
"/interface"
)
client
.
Use
(
aes
.
Aes
())
client
.
GET
(
"/news"
,
app
.
GetNews
)
client
.
GET
(
"/one-news"
,
app
.
GetOneNews
)
client
.
GET
(
"/articles"
,
app
.
GetArticle
)
...
...
@@ -35,7 +37,7 @@ func InitRouter() *gin.Engine {
client
.
GET
(
"/live-categories"
,
app
.
GetLiveCategories
)
client
.
GET
(
"/transaction-fee"
,
app
.
GetTransactionFee
)
client
.
GET
(
"/app/expired"
,
app
.
AppExpired
)
client
.
Use
(
aes
.
Aes
())
client
.
POST
(
"/user"
,
app
.
AddUser
)
api
:=
r
.
Group
(
"/api"
)
...
...
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