Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ( ErrInvalidCiphertext = errors.New("invalid ciphertext") ErrInvalidKey = errors.New("invalid key") ErrInvalidNonce = errors.New("invalid nonce") )
Common errors
Functions ¶
func GenerateKey ¶
GenerateKey generates a cryptographically secure random key
func GenerateKey256 ¶
GenerateKey256 generates a 256-bit key suitable for AES-256 or ChaCha20
Types ¶
type AESGCMCipher ¶
type AESGCMCipher struct {
// contains filtered or unexported fields
}
AESGCMCipher implements AES-256-GCM encryption
func NewAESGCM ¶
func NewAESGCM(key []byte, opts ...AESGCMOption) (*AESGCMCipher, error)
NewAESGCM creates a new AES-256-GCM cipher with secure defaults
type AESGCMOption ¶
type AESGCMOption func(*AESGCMCipher)
AESGCMOption configures AES-GCM parameters
func WithAESGCMNonceSize ¶
func WithAESGCMNonceSize(size int) AESGCMOption
WithAESGCMNonceSize sets custom nonce size (default: 12 bytes)
func WithAESGCMTagSize ¶
func WithAESGCMTagSize(size int) AESGCMOption
WithAESGCMTagSize sets custom tag size (default: 16 bytes)
type Argon2idCipher ¶
type Argon2idCipher struct {
// contains filtered or unexported fields
}
Argon2idCipher implements password-based encryption using Argon2id + AES-256-GCM
func NewArgon2id ¶
func NewArgon2id(password []byte, opts ...Argon2idOption) (*Argon2idCipher, error)
NewArgon2id creates a new Argon2id-based cipher with secure 2025 defaults
type Argon2idOption ¶
type Argon2idOption func(*Argon2idCipher)
Argon2idOption configures Argon2id parameters
func WithArgon2idMemory ¶
func WithArgon2idMemory(memory uint32) Argon2idOption
WithArgon2idMemory sets the memory parameter in KiB
func WithArgon2idSaltSize ¶
func WithArgon2idSaltSize(size int) Argon2idOption
WithArgon2idSaltSize sets the salt size in bytes
func WithArgon2idThreads ¶
func WithArgon2idThreads(threads uint8) Argon2idOption
WithArgon2idThreads sets the parallelism parameter
func WithArgon2idTime ¶
func WithArgon2idTime(time uint32) Argon2idOption
WithArgon2idTime sets the time parameter (iterations)
type ChaCha20Cipher ¶
type ChaCha20Cipher struct {
// contains filtered or unexported fields
}
ChaCha20Cipher implements ChaCha20-Poly1305 AEAD encryption
func NewChaCha20 ¶
func NewChaCha20(key []byte, opts ...ChaCha20Option) (*ChaCha20Cipher, error)
NewChaCha20 creates a new ChaCha20-Poly1305 cipher
type ChaCha20Option ¶
type ChaCha20Option func(*ChaCha20Cipher)
ChaCha20Option configures ChaCha20-Poly1305 parameters
type Cipher ¶
type Cipher interface {
Encrypt(plaintext []byte) ([]byte, error)
Decrypt(ciphertext []byte) ([]byte, error)
}
Cipher defines the interface for encryption/decryption operations
type PBKDF2Cipher ¶
type PBKDF2Cipher struct {
// contains filtered or unexported fields
}
PBKDF2Cipher implements password-based encryption using PBKDF2 + AES-256-GCM
func NewPBKDF2 ¶
func NewPBKDF2(password []byte, opts ...PBKDF2Option) (*PBKDF2Cipher, error)
NewPBKDF2 creates a new PBKDF2-based cipher with secure 2025 defaults
type PBKDF2Option ¶
type PBKDF2Option func(*PBKDF2Cipher)
PBKDF2Option configures PBKDF2 parameters
func WithPBKDF2Hash ¶
func WithPBKDF2Hash(hashFunc func() hash.Hash) PBKDF2Option
WithPBKDF2Hash sets the hash function (default: SHA-256)
func WithPBKDF2Iterations ¶
func WithPBKDF2Iterations(iterations int) PBKDF2Option
WithPBKDF2Iterations sets the iteration count
func WithPBKDF2SaltSize ¶
func WithPBKDF2SaltSize(size int) PBKDF2Option
WithPBKDF2SaltSize sets the salt size in bytes