gopbkdf2

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 22, 2023 License: MIT Imports: 4 Imported by: 0

README

gopbkdf2

Keycloak 암호화 모듈중 PBKDF2-SHA256 알고리즘구현을 위한 Wrapper 라이브러리

example

  • Hash a Password
package main

import(
	"fmt"
	"crypto/sha256"
	"github.com/parjom/gopbkdf2"
)

func main(){
	saltsize := 16
	keysize := 64
	iteration := 27500

	pass := gopbkdf2.NewPassword(sha256.New, saltsize, keysize, iteration)
	hashed := pass.HashPassword("p@ssw0rd")
	fmt.Println(hashed.CipherText) // base64 string
	fmt.Println(hashed.Salt)       // base64 string
}
  • Verify a Password
package main

import(
	"fmt"
	"crypto/sha256"
	"github.com/parjom/gopbkdf2"
)

func main(){
	saltsize := 16
	keysize := 64
	iteration := 27500

	pass := gopbkdf2.NewPassword(sha256.New, saltsize, keysize, iteration)
	hashed := pass.HashPassword("p@ssw0rd")
	fmt.Println(hashed.CipherText) // base64 string
	fmt.Println(hashed.Salt)       // base64 string

	isValid := pass.VerifyPassword("p@ssw0rd", hashed.CipherText, hashed.Salt)

	fmt.Println(isValid)
}

Documentation

Index

Constants

View Source
const (
	// MinSaltSize a minimum salt size recommended by the RFC
	MinSaltSize = 8
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HashResult

type HashResult struct {
	CipherText string
	Salt       string
}

type Password

type Password struct {
	HashFunc   func() hash.Hash
	SaltSize   int
	KeyLen     int
	Iterations int
}

func NewPassword

func NewPassword(hashFunc func() hash.Hash, saltSize int, keyLen int, iter int) *Password

func (*Password) GenSalt

func (p *Password) GenSalt() (string, error)

func (*Password) HashPassword

func (p *Password) HashPassword(password string) HashResult

func (*Password) VerifyPassword

func (p *Password) VerifyPassword(password, cipherText, salt string) bool

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL