hasher

package
v0.0.0-...-04f3e75 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InfoAuth = "auth"
)

Variables

This section is empty.

Functions

func DeriveKeyFromHash

func DeriveKeyFromHash(secret []byte, info string) ([]byte, error)

Types

type Hash

type Hash struct {
	Alg        string
	TimeCost   uint32
	MemoryCost uint32
	Threads    uint8
	Info       string
	Hash       []byte
	Salt       []byte
}

Hash represents a password hash derived from `Argon2id` and HKDF

func NewFromHash

func NewFromHash(hash string) (*Hash, error)

NewFromHash created a new hash from an existing password hash

func (*Hash) String

func (h *Hash) String() string

String return an encoded password hash

func (*Hash) Verify

func (h *Hash) Verify(password string) bool

Verify if a password hash matches the provided password

type Hasher

type Hasher struct {
	TimeCost   uint32
	MemoryCost uint32
	Threads    uint8
	Info       string
	Salt       []byte
	// contains filtered or unexported fields
}

func NewHasher

func NewHasher(password string, opts ...Option) (*Hasher, error)

NewHasher returns a new Hasher with the given password and options. The hasher can be used to either generate a new hash (for auth) or derive a secret key.

func (*Hasher) DeriveKey

func (h *Hasher) DeriveKey(info string) ([]byte, error)

DeriveKey derives a new key from the password hash.

func (*Hasher) Hash

func (h *Hasher) Hash() (*Hash, error)

Hash generates a new hash that can be used for authentication.

type Option

type Option func(*Hasher)

func WithDefaultOpts

func WithDefaultOpts() Option

func WithParameters

func WithParameters(timeCost uint32, memoryCost uint32, threads uint8) Option

WithParameters allow to change the default parameters for the hash.

func WithSalt

func WithSalt(salt []byte) Option

WithSalt sets the salt to use for the hash.

Jump to

Keyboard shortcuts

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