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
3ca23f52
Commit
3ca23f52
authored
Dec 17, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/manage-user' into 'develop'
钱包用户管理 See merge request
!2
parents
46d148f2
54276faa
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
config.go
conf/config.go
+2
-0
go.mod
go.mod
+1
-0
encrypt.go
pkg/encrypt/encrypt.go
+12
-0
No files found.
conf/config.go
View file @
3ca23f52
...
...
@@ -16,4 +16,6 @@ const (
// RSA Private File
AppRsaPrivateFile
=
"rsa/private.pem"
PASSWORD_DEFAULT
=
1
)
go.mod
View file @
3ca23f52
...
...
@@ -28,6 +28,7 @@ require (
github.com/satori/go.uuid v1.2.0 // indirect
github.com/valyala/fasttemplate v1.1.0 // indirect
github.com/xinliangnote/go-util v0.0.0-20200323134426-527984dc34bf
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 // indirect
gopkg.in/go-playground/validator.v9 v9.29.1
gopkg.in/ini.v1 v1.51.1 // indirect
...
...
pkg/encrypt/encrypt.go
View file @
3ca23f52
package
encrypt
import
(
config
"bwallet/conf"
"bytes"
"crypto/aes"
"crypto/cipher"
"encoding/base64"
"golang.org/x/crypto/bcrypt"
)
// 加密 aes_128_cbc
...
...
@@ -55,3 +57,13 @@ func pkcs5UnPadding(decrypted []byte) []byte {
unPadding
:=
int
(
decrypted
[
length
-
1
])
return
decrypted
[
:
(
length
-
unPadding
)]
}
func
HashPassword
(
password
string
)
(
string
,
error
)
{
bytes
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
password
),
config
.
PASSWORD_DEFAULT
)
return
string
(
bytes
),
err
}
func
CheckPasswordHash
(
password
,
hash
string
)
bool
{
err
:=
bcrypt
.
CompareHashAndPassword
([]
byte
(
hash
),
[]
byte
(
password
))
return
err
==
nil
}
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