Documentation
¶
Index ¶
Constants ¶
View Source
const ( // SaltSize is the length of a random salt in bytes. SaltSize = 16 // MinPassphraseLen is the minimum acceptable passphrase length. MinPassphraseLen = 8 )
Variables ¶
This section is empty.
Functions ¶
func Decrypt ¶
Decrypt splits the salt from the blob, re-derives the key, and decrypts ciphertext produced by Encrypt. The type parameter controls the return type.
Example usage:
plaintext, err := encrypt.Decrypt[[]byte]("my-passphrase", blob)
text, err := encrypt.Decrypt[string]("my-passphrase", blob)
func Encrypt ¶
Encrypt generates a fresh salt, derives a key from the passphrase, and encrypts plaintext using AES-256-GCM. The returned blob is:
salt (16 bytes) || nonce (12 bytes) || ciphertext + tag
Example usage:
blob, err := encrypt.Encrypt("my-passphrase", []byte("secret"))
blob, err := encrypt.Encrypt("my-passphrase", "secret")
func GenerateSalt ¶
GenerateSalt returns a cryptographically random 16-byte salt.
func ValidatePassphrase ¶
ValidatePassphrase checks that the passphrase meets minimum security requirements: non-empty, not whitespace-only, and at least MinPassphraseLen characters long.
Types ¶
Click to show internal directories.
Click to hide internal directories.