Documentation
¶
Index ¶
- Variables
- func GenerateKey(size int) (string, error)
- func GenerateKey256() (string, error)
- type Encrypter
- func (e *Encrypter) Decrypt(ciphertext []byte) ([]byte, error)
- func (e *Encrypter) DecryptString(encoded string) (string, error)
- func (e *Encrypter) Encrypt(plaintext []byte) ([]byte, error)
- func (e *Encrypter) EncryptDeterministicUNSAFE(plaintext []byte) ([]byte, error)
- func (e *Encrypter) EncryptString(plaintext string) (string, error)
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func GenerateKey ¶
GenerateKey generates a random key of the given byte length (16/24/32) and returns it hex-encoded.
func GenerateKey256 ¶
GenerateKey256 generates a random 32-byte AES-256 key (hex-encoded).
Types ¶
type Encrypter ¶
type Encrypter struct {
// contains filtered or unexported fields
}
Encrypter provides AES-256-GCM authenticated encryption.
func New ¶
New creates an Encrypter. key must be 16/24/32 bytes. You can pass a hex-encoded or base64-encoded key — it will be decoded automatically.
func (*Encrypter) DecryptString ¶
DecryptString decrypts a base64-encoded ciphertext produced by EncryptString.
func (*Encrypter) EncryptDeterministicUNSAFE ¶
EncryptDeterministicUNSAFE encrypts with a zero nonce (same input → same output). SECURITY WARNING: Using AES-GCM with a zero nonce is cryptographically unsafe as it leaks information about identical plaintexts and enables key recovery attacks. DO NOT use for general-purpose encryption; only use when deterministic ciphertexts are strictly required (e.g. for exact match queries on searchable columns).