crypto

package
v0.0.0 Latest Latest
Warning

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

Go to latest
Published: Jan 11, 2026 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKeySize     = errors.New("key must be 32 bytes")
	ErrCiphertextTooShort = errors.New("ciphertext too short")
)

Encryption errors.

View Source
var (
	ErrInvalidHashFormat   = errors.New("invalid hash format")
	ErrUnsupportedHashAlgo = errors.New("unsupported hash algorithm")
)

Hash errors.

Functions

func DatabaseAAD

func DatabaseAAD(databaseUID string) []byte

DatabaseAAD returns the AAD for encrypting database credentials. This binds the ciphertext to a specific database UID, preventing credential transplant attacks where encrypted passwords are swapped between database rows.

func Decrypt

func Decrypt(ciphertext []byte, key []byte, aad []byte) ([]byte, error)

Decrypt decrypts ciphertext using AES-256-GCM with the provided key. The ciphertext must include the nonce prefix. The aad must match the value used during encryption, or be nil for legacy data.

func Encrypt

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

Encrypt encrypts plaintext using AES-256-GCM with the provided key. The ciphertext includes the nonce prefix. Optional aad (Additional Authenticated Data) binds the ciphertext to a context, preventing the ciphertext from being used in a different context.

func HashPassword

func HashPassword(password string) (string, error)

HashPassword generates an Argon2id hash of the password.

func VerifyPassword

func VerifyPassword(encodedHash, password string) (bool, error)

VerifyPassword verifies a password against an Argon2id hash.

Types

This section is empty.

Jump to

Keyboard shortcuts

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