utils

package
v0.0.0-...-6efd311 Latest Latest
Warning

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

Go to latest
Published: Apr 30, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultArgon2IDParameters = Argon2IDParameters{
	SaltLength: 16,
	Time:       2,
	Memory:     19 * 1024,
	Threads:    1,
	KeyLength:  32,
}

Default parameters recommended by OWASP

View Source
var ErrInvalidPassword = errors.New("invalid password")

Functions

func CompareHashAndPassword

func CompareHashAndPassword(hashedPassword string, password string) error

CompareHashAndPassword takes a hashed password string and a password, hashes the password with the same parameters as the hashed password and compares the resulting value, returning an error if they do not match.

When this function is passed an invalid hashed password string, it will hash the password with the default parameters to prevent an attacker from getting information from the timing of a login failure.

func Decrypt

func Decrypt(encryptedString string, key []byte) (string, error)

Decrypt decrypts a base64-encoded encrypted string using AES-256-GCM. The key must be the same 32-byte key used for encryption.

func Encrypt

func Encrypt(plaintext string, key []byte) (string, error)

Encrypt encrypts a string using AES-256-GCM. The key must be 32 bytes (256 bits) long. Returns base64-encoded encrypted string.

func GenerateAES256GCMEncryptionKey

func GenerateAES256GCMEncryptionKey() (encryptionKey []byte, err error)

func HashPassword

func HashPassword(password string) (string, error)

Takes the password string, makes sure it's not empty, and hashes it using argon2id

Types

type Argon2IDParameters

type Argon2IDParameters struct {
	SaltLength uint32 // bytes
	Time       uint32 // time factor in number of iterations
	Memory     uint32 // kibibytes
	Threads    uint8  // number of threads
	KeyLength  uint32 // bytes
}

Jump to

Keyboard shortcuts

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