Versions in this module Expand all Collapse all v0 v0.0.7 Aug 18, 2026 Changes in this version + var ErrDecryptionFailed = errors.New("fallo al descifrar los datos") + var ErrEncryptionFailed = errors.New("fallo al cifrar los datos") + var ErrInvalidCiphertext = errors.New("formato de texto cifrado inválido") + var ErrInvalidHash = errors.New("formato de hash inválido") + var ErrInvalidKeyLength = errors.New("la clave debe tener exactamente 32 bytes para AES-256") + var ErrInvalidLength = errors.New("la longitud debe ser mayor que cero") + var ErrInvalidPrefix = errors.New("el prefijo debe ser alfanumérico") + var ErrPasswordTooLong = errors.New("la contraseña es demasiado larga") + var ErrPasswordTooShort = errors.New("la contraseña es demasiado corta") + var ErrRandomGenerationFailed = errors.New("fallo al generar datos aleatorios seguros") + var ErrUnsupportedAlgorithm = errors.New("algoritmo de hashing no soportado") + func DecryptBytes(ciphertext string) ([]byte, error) + func DecryptString(ciphertext string) (string, error) + func DecryptWithKey(ciphertext string, key []byte) (string, error) + func EncryptBytes(plaintext []byte) (string, error) + func EncryptString(plaintext string) (string, error) + func EncryptWithKey(plaintext string, key []byte) (string, error) + func GenerateAPIKey(prefix string) (string, error) + func GenerateAPIKeyWithPrefix(prefix string) (string, error) + func GenerateEncryptionKey() ([]byte, error) + func GenerateEncryptionKeyBase64() (string, error) + func GenerateNumericCode(length int) (string, error) + func GenerateOTP(length int) (string, error) + func GenerateRandomBytes(n int) ([]byte, error) + func GenerateRandomString(n int) (string, error) + func GenerateSecureToken() (string, error) + func GenerateUUID() (string, error) + func GenerateUUIDv4() (string, error) + func HashPassword(password string) (string, error) + func HashWithArgon2id(password string) (string, error) + func HashWithBcrypt(password string) (string, error) + func HashWithPBKDF2(password string) (string, error) + func HashWithScrypt(password string) (string, error) + func NeedsUpgrade(storedHash string) bool + func RandomBytes(n int) ([]byte, error) + func RandomHex(n int) (string, error) + func RandomString(n int) (string, error) + func SetDefaultHasher(hasher Hasher) + func SetEncryptionKey(key []byte) error + func VerifyPassword(password, storedHash string) (bool, error) + type AESEncrypter struct + func NewAESEncrypter(key []byte) (*AESEncrypter, error) + func (e *AESEncrypter) Decrypt(ciphertext string) ([]byte, error) + func (e *AESEncrypter) DecryptString(ciphertext string) (string, error) + func (e *AESEncrypter) Encrypt(plaintext []byte) (string, error) + func (e *AESEncrypter) EncryptString(plaintext string) (string, error) + type Algorithm string + const AlgorithmArgon2id + const AlgorithmBcrypt + const AlgorithmPBKDF2 + const AlgorithmScrypt + func DetectAlgorithm(hash string) (Algorithm, error) + type Argon2Hasher struct + func NewArgon2Hasher(cfg HasherConfig) (*Argon2Hasher, error) + func (h *Argon2Hasher) Hash(password string) (string, error) + func (h *Argon2Hasher) NeedsUpgrade(hash string) bool + func (h *Argon2Hasher) Verify(password, hash string) (bool, error) + type BcryptHasher struct + func NewBcryptHasher(cfg HasherConfig) (*BcryptHasher, error) + func (h *BcryptHasher) Hash(password string) (string, error) + func (h *BcryptHasher) NeedsUpgrade(hash string) bool + func (h *BcryptHasher) Verify(password, hash string) (bool, error) + type Encrypter interface + Decrypt func(ciphertext string) ([]byte, error) + DecryptString func(ciphertext string) (string, error) + Encrypt func(plaintext []byte) (string, error) + EncryptString func(plaintext string) (string, error) + type Hasher interface + Hash func(password string) (string, error) + NeedsUpgrade func(hash string) bool + Verify func(password, hash string) (bool, error) + func NewHasher(cfg HasherConfig) (Hasher, error) + type HasherConfig struct + Algorithm Algorithm + Argon2Iterations uint32 + Argon2KeyLength uint32 + Argon2Memory uint32 + Argon2Parallelism uint8 + Argon2SaltLength uint32 + BcryptCost int + PBKDF2Iterations int + PBKDF2KeyLen int + PBKDF2SaltLen int + ScryptKeyLen int + ScryptN int + ScryptP int + ScryptR int + ScryptSaltLen int + type PBKDF2Hasher struct + func NewPBKDF2Hasher(cfg HasherConfig) (*PBKDF2Hasher, error) + func (h *PBKDF2Hasher) Hash(password string) (string, error) + func (h *PBKDF2Hasher) NeedsUpgrade(hash string) bool + func (h *PBKDF2Hasher) Verify(password, hash string) (bool, error) + type ScryptHasher struct + func NewScryptHasher(cfg HasherConfig) (*ScryptHasher, error) + func (h *ScryptHasher) Hash(password string) (string, error) + func (h *ScryptHasher) NeedsUpgrade(hash string) bool + func (h *ScryptHasher) Verify(password, hash string) (bool, error)