密码从string改为[]byte类型

This commit is contained in:
xiaoqidun 2020-01-07 10:31:00 +08:00
parent 5ebdc04340
commit 5dcac0a3fb
2 changed files with 6 additions and 6 deletions

@ -5,7 +5,7 @@ go get -u github.com/xiaoqidun/idkey
# 使用方法
```go
// 生成argon2id hash密码
hash := idkey.Encode("admin")
hash := idkey.Encode([]byte("admin"))
// 进行argon2id hash验证
verify := idkey.Verify("admin", hash)
verify := idkey.Verify([]byte("admin"), hash)
```

@ -19,7 +19,7 @@ type Data struct {
KeyLen uint32 // 密文长度
}
func Encode(password string) string {
func Encode(password []byte) string {
salt := generateSalt(16)
data := &Data{
Hash: nil,
@ -30,7 +30,7 @@ func Encode(password string) string {
KeyLen: 32,
}
hash := argon2.IDKey(
[]byte(password),
password,
data.Salt,
data.Time,
data.Memory,
@ -92,13 +92,13 @@ func Decode(passwordHash string) (data *Data, err error) {
return
}
func Verify(password, passwordHash string) bool {
func Verify(password []byte, passwordHash string) bool {
data, err := Decode(passwordHash)
if err != nil {
return false
}
hash := argon2.IDKey(
[]byte(password),
password,
data.Salt,
data.Time,
data.Memory,