Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
go-cqhttp
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
go-cqhttp
Commits
44b26b70
Commit
44b26b70
authored
Aug 10, 2020
by
Mrs4s
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
password encrypt supported. close #22
parent
97f7de85
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
11 deletions
+59
-11
global/config.go
global/config.go
+12
-10
main.go
main.go
+47
-1
No files found.
global/config.go
View file @
44b26b70
...
...
@@ -6,16 +6,18 @@ import (
)
type
JsonConfig
struct
{
Uin
int64
`json:"uin"`
Password
string
`json:"password"`
EnableDB
bool
`json:"enable_db"`
AccessToken
string
`json:"access_token"`
ReLogin
bool
`json:"relogin"`
ReLoginDelay
int
`json:"relogin_delay"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
Debug
bool
`json:"debug"`
Uin
int64
`json:"uin"`
Password
string
`json:"password"`
EncryptPassword
bool
`json:"encrypt_password"`
PasswordEncrypted
string
`json:"password_encrypted"`
EnableDB
bool
`json:"enable_db"`
AccessToken
string
`json:"access_token"`
ReLogin
bool
`json:"relogin"`
ReLoginDelay
int
`json:"relogin_delay"`
HttpConfig
*
GoCQHttpConfig
`json:"http_config"`
WSConfig
*
GoCQWebsocketConfig
`json:"ws_config"`
ReverseServers
[]
*
GoCQReverseWebsocketConfig
`json:"ws_reverse_servers"`
Debug
bool
`json:"debug"`
}
type
CQHttpApiConfig
struct
{
...
...
main.go
View file @
44b26b70
...
...
@@ -3,8 +3,11 @@ package main
import
(
"bufio"
"bytes"
"crypto/md5"
"encoding/base64"
"encoding/json"
"fmt"
"github.com/Mrs4s/MiraiGo/binary"
"github.com/Mrs4s/MiraiGo/client"
"github.com/Mrs4s/go-cqhttp/coolq"
"github.com/Mrs4s/go-cqhttp/global"
...
...
@@ -112,7 +115,7 @@ func main() {
time
.
Sleep
(
time
.
Second
*
5
)
return
}
if
conf
.
Uin
==
0
||
conf
.
Password
==
""
{
if
conf
.
Uin
==
0
||
(
conf
.
Password
==
""
&&
conf
.
PasswordEncrypted
==
""
)
{
log
.
Warnf
(
"请修改 config.json 以添加账号密码."
)
time
.
Sleep
(
time
.
Second
*
5
)
return
...
...
@@ -132,6 +135,24 @@ func main() {
log
.
Fatalf
(
"加载设备信息失败: %v"
,
err
)
}
}
if
conf
.
EncryptPassword
&&
conf
.
PasswordEncrypted
==
""
{
log
.
Infof
(
"密码加密已启用, 请输入Key对密码进行加密: (Enter 提交)"
)
strKey
,
_
:=
console
.
ReadString
(
'\n'
)
key
:=
md5
.
Sum
([]
byte
(
strKey
))
if
encrypted
:=
EncryptPwd
(
conf
.
Password
,
key
[
:
]);
encrypted
!=
""
{
conf
.
Password
=
""
conf
.
PasswordEncrypted
=
encrypted
_
=
conf
.
Save
(
"config.json"
)
}
else
{
log
.
Warnf
(
"加密时出现问题."
)
}
}
if
conf
.
PasswordEncrypted
!=
""
{
log
.
Infof
(
"密码加密已启用, 请输入Key对密码进行解密以继续: (Enter 提交)"
)
strKey
,
_
:=
console
.
ReadString
(
'\n'
)
key
:=
md5
.
Sum
([]
byte
(
strKey
))
conf
.
Password
=
DecryptPwd
(
conf
.
PasswordEncrypted
,
key
[
:
])
}
log
.
Info
(
"Bot将在5秒后登录并开始信息处理, 按 Ctrl+C 取消."
)
time
.
Sleep
(
time
.
Second
*
5
)
log
.
Info
(
"开始尝试登录并同步消息..."
)
...
...
@@ -210,3 +231,28 @@ func main() {
<-
c
b
.
Release
()
}
func
EncryptPwd
(
pwd
string
,
key
[]
byte
)
string
{
tea
:=
binary
.
NewTeaCipher
(
key
)
if
tea
==
nil
{
return
""
}
return
base64
.
StdEncoding
.
EncodeToString
(
tea
.
Encrypt
([]
byte
(
pwd
)))
}
func
DecryptPwd
(
ePwd
string
,
key
[]
byte
)
string
{
defer
func
()
{
if
pan
:=
recover
();
pan
!=
nil
{
log
.
Fatalf
(
"密码解密失败: %v"
,
pan
)
}
}()
encrypted
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
ePwd
)
if
err
!=
nil
{
panic
(
err
)
}
tea
:=
binary
.
NewTeaCipher
(
key
)
if
tea
==
nil
{
panic
(
"密钥错误"
)
}
return
string
(
tea
.
Decrypt
(
encrypted
))
}
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