crypto

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 2, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package crypto provides functions for encrypting and decrypting data using AES-256-GCM with keys derived from passwords using Argon2id.

Index

Constants

View Source
const (
	// Argon2Time is the time cost parameter for Argon2id key derivation.
	Argon2Time = 3
	// Argon2Memory is the memory cost parameter for Argon2id key derivation.
	Argon2Memory = 64 * 1024 // 64 MB.
	// Argon2Threads is the parallelism parameter for Argon2id key derivation.
	Argon2Threads = 4
	// Argon2KeyLen is the key length for AES-256.
	Argon2KeyLen = 32 // 256 bits for AES-256.
	// SaltSize is the size of the salt in bytes.
	SaltSize = 16
	// GCMNonceSize is the size of the GCM nonce in bytes.
	GCMNonceSize = 12
	// GCMTagSize is the size of the GCM authentication tag in bytes.
	GCMTagSize = 16
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(encryptedB64, password string) (string, error)

Decrypt decrypts AES-256-GCM encrypted data. Expects: base64(salt + nonce + ciphertext + tag)

func DeriveKey

func DeriveKey(password, salt []byte) []byte

DeriveKey derives a 32-byte key from the password using Argon2id.

func Encrypt

func Encrypt(plaintext, password string) (string, error)

Encrypt encrypts data using AES-256-GCM. Returns: base64(salt + nonce + ciphertext + tag)

func GenerateRandomBytes

func GenerateRandomBytes(n int) ([]byte, error)

GenerateRandomBytes generates random bytes for IV/nonce.

func GenerateSalt

func GenerateSalt() ([]byte, error)

GenerateSalt generates a random salt for key derivation.

func HashPassword

func HashPassword(password string) string

HashPassword creates a SHA-256 hash for password validation (not for encryption).

func ValidatePassword

func ValidatePassword(password, storedHash string) bool

ValidatePassword checks if the provided password matches the stored hash.

Types

This section is empty.

Jump to

Keyboard shortcuts

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