Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
I
im-pool
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
haoyanbin
im-pool
Commits
3239132a
Commit
3239132a
authored
Oct 14, 2022
by
haoyanbin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
aes
parent
ab2296fa
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
128 additions
and
7 deletions
+128
-7
aes.go
pool/aes.go
+110
-0
publicApi.go
pool/publicApi.go
+11
-0
ws_server.go
ws_server.go
+7
-7
No files found.
pool/aes.go
0 → 100644
View file @
3239132a
package
pool
import
(
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"strings"
)
//aes-cbc 密码 偏移量 base64 utf8
const
certKey
=
"dbc88888dbc88888"
func
PKCS5Padding
(
ciphertext
[]
byte
,
blockSize
int
)
[]
byte
{
padding
:=
blockSize
-
len
(
ciphertext
)
%
blockSize
padtext
:=
bytes
.
Repeat
([]
byte
{
byte
(
padding
)},
padding
)
return
append
(
ciphertext
,
padtext
...
)
}
func
ZEROPadding
(
ciphertext
[]
byte
,
blockSize
int
)
[]
byte
{
padding
:=
blockSize
-
len
(
ciphertext
)
%
blockSize
padtext
:=
bytes
.
Repeat
([]
byte
{
0
},
padding
)
//用0去填充
return
append
(
ciphertext
,
padtext
...
)
}
func
PKCS5UnPadding
(
origData
[]
byte
)
[]
byte
{
length
:=
len
(
origData
)
unpadding
:=
int
(
origData
[
length
-
1
])
return
origData
[
:
(
length
-
unpadding
)]
}
//加密 aes-cbc-128
func
AesEncrypt
(
origData
,
key
[]
byte
)
([]
byte
,
error
)
{
block
,
err
:=
aes
.
NewCipher
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
blockSize
:=
block
.
BlockSize
()
origData
=
PKCS5Padding
(
origData
,
blockSize
)
blockMode
:=
cipher
.
NewCBCEncrypter
(
block
,
key
[
:
blockSize
])
crypted
:=
make
([]
byte
,
len
(
origData
))
blockMode
.
CryptBlocks
(
crypted
,
origData
)
return
crypted
,
nil
}
//解密 aes-cbc-128
func
AesDecrypt
(
crypted
,
key
[]
byte
)
([]
byte
,
error
)
{
block
,
err
:=
aes
.
NewCipher
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
blockSize
:=
block
.
BlockSize
()
blockMode
:=
cipher
.
NewCBCDecrypter
(
block
,
key
[
:
blockSize
])
origData
:=
make
([]
byte
,
len
(
crypted
))
blockMode
.
CryptBlocks
(
origData
,
crypted
)
origData
=
PKCS5UnPadding
(
origData
)
return
origData
,
nil
}
// 数据加密
func
DataAesEncrypt
(
Data
string
)
(
string
,
error
)
{
data
:=
[]
byte
(
Data
)
xpass
,
err
:=
AesEncrypt
(
data
,
[]
byte
(
certKey
))
if
err
!=
nil
{
return
""
,
err
}
pass64
:=
base64
.
StdEncoding
.
EncodeToString
(
xpass
)
return
pass64
,
nil
}
// 数据解密
func
DataAesDecrypt
(
Data
string
)
(
string
,
error
)
{
Data
=
strings
.
Replace
(
Data
,
" "
,
""
,
-
1
)
bytesPass
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
Data
)
xpass
,
err
:=
AesDecrypt
(
bytesPass
,
[]
byte
(
certKey
))
if
err
!=
nil
{
return
""
,
err
}
return
string
(
xpass
[
:
]),
nil
}
// 数据加密
func
TestDataAesEncrypt
(
Data
string
)
(
int
,
string
,
error
)
{
data
:=
[]
byte
(
Data
)
xpass
,
err
:=
TestAesEncrypt
(
data
,
[]
byte
(
certKey
))
if
err
!=
nil
{
return
0
,
""
,
err
}
pass64
:=
base64
.
StdEncoding
.
EncodeToString
(
xpass
)
return
1
,
pass64
,
nil
}
//加密 aes-cbc-128
func
TestAesEncrypt
(
origData
,
key
[]
byte
)
([]
byte
,
error
)
{
block
,
err
:=
aes
.
NewCipher
(
key
)
if
err
!=
nil
{
return
nil
,
err
}
blockSize
:=
block
.
BlockSize
()
origData
=
ZEROPadding
(
origData
,
blockSize
)
blockMode
:=
cipher
.
NewCBCEncrypter
(
block
,
key
[
:
blockSize
])
crypted
:=
make
([]
byte
,
len
(
origData
))
blockMode
.
CryptBlocks
(
crypted
,
origData
)
return
crypted
,
nil
}
pool/publicApi.go
View file @
3239132a
...
...
@@ -306,6 +306,15 @@ func GetClientInfoByToken(token string) (*UserInfo, error) {
return
nil
,
errors
.
New
(
"用户数据有误"
)
}
source
,
err
:=
DataAesDecrypt
(
tokenData
[
0
])
if
err
!=
nil
{
return
nil
,
errors
.
New
(
"用户数据有误"
)
}
if
len
(
source
)
<=
0
{
return
nil
,
errors
.
New
(
"用户数据有误"
)
}
userData
:=
new
(
UserInfo
)
userData
.
Source
=
tokenData
[
0
]
userData
.
Promoter
=
tokenData
[
1
]
...
...
@@ -341,6 +350,8 @@ func SaveMsg(msg *SendMsg) {
mqData
.
UserId
=
user
.
CustomerId
}
mqData
.
BusinessId
,
_
=
DataAesDecrypt
(
mqData
.
BusinessId
)
mqData
.
ProcedureType
=
msg
.
ProcedureType
mqData
.
StartTime
=
msg
.
SendTime
...
...
ws_server.go
View file @
3239132a
...
...
@@ -133,16 +133,16 @@ func ws(w http.ResponseWriter, r *http.Request) {
closeMsg
.
Finish
=
"3"
closeMsg
.
BusinessId
=
userInfo
.
Source
closeMsg
.
CustomerId
=
userInfo
.
CustomerId
//
pool.PublishData(closeMsg)
fmt
.
Println
(
"用户关闭连接"
,
client
.
Id
)
pool
.
PublishData
(
closeMsg
)
fmt
.
Println
(
"用户关闭连接"
,
client
.
Id
)
}
if
user
.
Promoter
==
"2"
{
//
closeMsg.Finish = "4"
//
closeMsg.GroupId = userInfo.Source
//
closeMsg.UserId = userInfo.CustomerId
//
pool.PublishData(closeMsg)
fmt
.
Println
(
"专家关闭连接"
,
client
.
Id
)
closeMsg
.
Finish
=
"4"
closeMsg
.
GroupId
=
userInfo
.
Source
closeMsg
.
UserId
=
userInfo
.
CustomerId
pool
.
PublishData
(
closeMsg
)
fmt
.
Println
(
"专家关闭连接"
,
client
.
Id
)
}
fmt
.
Printf
(
"连接己经关闭%s"
,
client
.
Id
)
...
...
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