Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/wuriyanto48/go-pbkdf2
a Go package for hash and verify a password using PBKDF2
https://github.com/wuriyanto48/go-pbkdf2
cryptography encrypt go golang golang-application golang-examples golang-library pbkdf2
Last synced: about 1 month ago
JSON representation
a Go package for hash and verify a password using PBKDF2
- Host: GitHub
- URL: https://github.com/wuriyanto48/go-pbkdf2
- Owner: wuriyanto48
- Created: 2017-05-01T08:22:05.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2022-10-15T06:17:40.000Z (about 2 years ago)
- Last Synced: 2024-09-29T21:21:37.971Z (about 2 months ago)
- Topics: cryptography, encrypt, go, golang, golang-application, golang-examples, golang-library, pbkdf2
- Language: Go
- Homepage:
- Size: 18.6 KB
- Stars: 11
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# GO PBKDF2
PBKDF2 (Password-Based Key Derivation Function 2) https://en.wikipedia.org/wiki/PBKDF2
[![Build Status](https://travis-ci.org/wuriyanto48/go-pbkdf2.svg?branch=master)](https://travis-ci.org/wuriyanto48/go-pbkdf2)
[![go-pbkdf2 CI](https://github.com/wuriyanto48/go-pbkdf2/actions/workflows/ci.yml/badge.svg)](https://github.com/wuriyanto48/go-pbkdf2/actions/workflows/ci.yml)**This Implementation Based On**
Package pbkdf2 implements the key derivation function PBKDF2 as defined in RFC 2898 / PKCS #5 v2.0.
https://godoc.org/golang.org/x/crypto/pbkdf2# USAGE
## Use as a library
- **Install:**
```shell
go get github.com/wuriyanto48/go-pbkdf2
```- **Hash a Password**
```go
package mainimport(
"fmt"
"crypto/sha1"
"github.com/wuriyanto48/go-pbkdf2"
)func main(){
pass := p.NewPassword(sha1.New, 8, 32,15000)
hashed := pass.HashPassword("123456")
fmt.Println(hashed.CipherText)
fmt.Println(hashed.Salt)
}
```- **Verify a Password**
```go
package mainimport(
"fmt"
"crypto/sha1"
"github.com/wuriyanto48/go-pbkdf2"
)func main(){
pass := p.NewPassword(sha1.New, 8, 32,15000)
hashed := pass.HashPassword("123456")
fmt.Println(hashed.CipherText)
fmt.Println(hashed.Salt)isValid := pass.VerifyPassword("123456", hashed.CipherText, hashed.Salt)
fmt.Println(isValid)
}
```## Use as a binary
build
```shell
$ make build
```show available options
```shell
$ ./go-pbkdf2 -h
```# Doc
- **func NewPassword**
```go
func NewPassword(func() hash.Hash, saltSize int, keyLen int, iterations int) *Password
```
the drafted v2.1 specification allows use of all five FIPS Approved
Hash Functions SHA-1, SHA-224, SHA-256, SHA-384 and SHA-512 for HMAC. To
choose, you can pass the `New` functions from the different SHA packages to
pbkdf2.Key.- **func HashPassword**
```go
func HashPassword("123456")
```
this function returning HashResult(struct) Which has two fields, CiphertText and Salt- **func VerifyPassword**
```go
func VerifyPassword("123456", hashed.CipherText, hashed.Salt) (bool)
```
this function returning true if your password is valid and false otherwise
##
Wuriyanto Musobar 2017