argon2

package module
v0.0.0-...-b4f6098 Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2024 License: MIT Imports: 7 Imported by: 0

README

go.b8s.dev/argon2

This package provides a user-friendly interface to generate argon2 hashes and digests, often useful for hashing secret values for safer storage.

Installation

go get -u go.b8s.dev/argon2

Usage

var d *argon2.Argon2Digest
var err error

// Hash a string value
h = argon2.NewFromString("passw0rd123")

h.String()
// => $argon2i$v=19$m=65536,t=2,p=4$c29tZXNhbHQ$RdescudvJCsgt3ub+b+dWRWJTmaaJObG

// Hash bytes directly, such as from `crypto/rand`
h = argon2.NewFromBytes([]byte{1,2,3})

// Restore an *Argon2Digest from its hash
d, err = argon2.NewFromEncoded("$argon2i$v=19$m=....")

// Compare a raw value against its hash
h.Compare("passw0rd123") // => true
h.Compare("s3cr3t!") // => false

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidHash         = errors.New("the encoded value is not in a supported format")
	ErrIncompatibleVersion = errors.New("incompatible version of argon2")
)

Functions

This section is empty.

Types

type Argon2Digest

type Argon2Digest struct {
	Digest []byte
	Salt   []byte
	// contains filtered or unexported fields
}

Argon2Digest stores the parameters and hash digest for a password.

func New

func New() *Argon2Digest

NewArgon2Digest generates an Argon2Digest struct using default params.

func NewFromBytes

func NewFromBytes(raw []byte) *Argon2Digest

func NewFromEncoded

func NewFromEncoded(encoded string) (*Argon2Digest, error)

func NewFromString

func NewFromString(raw string) *Argon2Digest

func (*Argon2Digest) Compare

func (a *Argon2Digest) Compare(raw string) bool

func (*Argon2Digest) CompareBytes

func (a *Argon2Digest) CompareBytes(raw []byte) bool

func (*Argon2Digest) GenerateDigest

func (a *Argon2Digest) GenerateDigest(raw []byte) error

func (*Argon2Digest) String

func (a *Argon2Digest) String() string

String encodes the Argon2 hash using the standard encoded representation, as per the official CLI: https://github.com/P-H-C/phc-winner-argon2/tree/f57e61e19229e23c4445b85494dbf7c07de721cb#command-line-utility

Jump to

Keyboard shortcuts

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