argon2id

package module
v0.0.0-...-1a25c3a Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2023 License: MIT Imports: 7 Imported by: 0

README

go-argon2id

Argon2id wrapper implementation over official Go argon2 package for convenience

Installation

go get -u github.com/notEpsilon/go-argon2id

Usage

import (
  "github.com/notEpsilon/go-argon2id"
)

hasher := argon2id.NewArgon2Id()

// hash password
hash, err := hasher.Hash("MyPassword123")
if err != nil {
  panic(err)
}

// compare password with a hash
match, err := hasher.Compare("MyPassword123", hash)
if err != nil {
  panic(err)
}

// ...

Advanced use with options

import (
  "github.com/notEpsilon/go-argon2id"
)

hasher := argon2id.NewArgon2Id()

// hash password with options
hash, err := hasher.Hash("MyPassword123", argon2id.Options{
  Iterations: 1,
  Memory: 64*1024,
  Threads: 2,
  SaltLength: 16,
  KeyLength: 32,
})

// or using the default options (this is used by default you don't need to provide it)
hash, err := hasher.Hash("MyPassword123", argon2id.DefaultOptions) // same as hasher.Hash("MyPassword123")

// ...

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultOptions = &Options{
		Iterations: 3,
		Memory:     64 * 1024,
		Threads:    4,
		SaltLength: 16,
		KeyLength:  32,
	}
)
View Source
var (
	ErrInvalidForm = errors.New("provided hash is in an invalid form")
)

Functions

This section is empty.

Types

type Argon2Hasher

type Argon2Hasher interface {
	Hash(string, ...*Options) (string, error)
	Compare(string, string) (bool, error)
	DecodeIntoOptions(string) (Options, []byte, []byte, error)
}

type Argon2Id

type Argon2Id struct{}

func NewArgon2Id

func NewArgon2Id() Argon2Id

func (Argon2Id) Compare

func (a Argon2Id) Compare(plain, hash string) (bool, error)

func (Argon2Id) DecodeIntoOptions

func (Argon2Id) DecodeIntoOptions(hash string) (Options, []byte, []byte, error)

func (Argon2Id) Hash

func (Argon2Id) Hash(plain string, options ...*Options) (string, error)

type Options

type Options struct {
	Iterations uint32
	Memory     uint32
	Threads    uint8
	SaltLength uint32
	KeyLength  uint32
}

Jump to

Keyboard shortcuts

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