From 5dcac0a3fbec7497807ec9dd627aa9a14836b740 Mon Sep 17 00:00:00 2001 From: xiaoqidun Date: Tue, 7 Jan 2020 10:31:00 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=86=E7=A0=81=E4=BB=8Estring=E6=94=B9?= =?UTF-8?q?=E4=B8=BA[]byte=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 ++-- idkey.go | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index f457e15..bdd5830 100644 --- a/README.md +++ b/README.md @@ -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) ``` diff --git a/idkey.go b/idkey.go index 92c51ab..1c980ce 100644 --- a/idkey.go +++ b/idkey.go @@ -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,