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,