mirror of
https://github.com/xiaoqidun/idkey.git
synced 2024-11-23 08:36:47 +08:00
docs(更新文档): 添加注释
This commit is contained in:
parent
010073a6c0
commit
4b6cac9d6f
@ -1,4 +1,4 @@
|
||||
# idkey
|
||||
# idkey[![PkgGoDev](https://pkg.go.dev/badge/github.com/xiaoqidun/idkey)](https://pkg.go.dev/github.com/xiaoqidun/idkey)
|
||||
Golang Argon2id 密码hash和验证
|
||||
# 安装方法
|
||||
go get -u github.com/xiaoqidun/idkey
|
||||
|
5
idkey.go
5
idkey.go
@ -10,12 +10,14 @@ import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Data 密码编码结构
|
||||
type Data struct {
|
||||
EncodeOptions // 加密选项
|
||||
Hash []byte // 密码密文
|
||||
Salt []byte // 加密盐值
|
||||
}
|
||||
|
||||
// EncodeOptions 密文编码选项
|
||||
type EncodeOptions struct {
|
||||
Time uint32 // 时间参数
|
||||
Memory uint32 // 内存参数
|
||||
@ -23,6 +25,7 @@ type EncodeOptions struct {
|
||||
KeyLen uint32 // 密文长度
|
||||
}
|
||||
|
||||
// Encode 将密码编码成密文
|
||||
func Encode(password []byte, options *EncodeOptions) string {
|
||||
salt := generateSalt(16)
|
||||
data := &Data{
|
||||
@ -58,6 +61,7 @@ func Encode(password []byte, options *EncodeOptions) string {
|
||||
)
|
||||
}
|
||||
|
||||
// Decode 获取密文的编码结构
|
||||
func Decode(passwordHash string) (data *Data, err error) {
|
||||
data = &Data{}
|
||||
params := strings.Split(passwordHash, "$")
|
||||
@ -102,6 +106,7 @@ func Decode(passwordHash string) (data *Data, err error) {
|
||||
return
|
||||
}
|
||||
|
||||
// Verify 验证密码编码后是否等于密文
|
||||
func Verify(password []byte, passwordHash string) bool {
|
||||
data, err := Decode(passwordHash)
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user