Documentation
¶
Overview ¶
Package encryption provides AES-GCM encryption and decryption for sensitive data in gokit applications.
It supports automatic key derivation from passphrases using SHA-256 hashing, producing 256-bit keys for AES-GCM authenticated encryption.
Usage ¶
enc, err := encryption.New("my-secret-passphrase")
ciphertext, err := enc.Encrypt(plaintext)
plaintext, err := enc.Decrypt(ciphertext)
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ChaCha20Service ¶
type ChaCha20Service struct {
// contains filtered or unexported fields
}
ChaCha20Service handles encryption/decryption using ChaCha20-Poly1305. This is a modern AEAD cipher that performs well on CPUs without AES hardware acceleration (e.g., ARM devices, older processors).
func NewChaCha20 ¶
func NewChaCha20(key string) (*ChaCha20Service, error)
NewChaCha20 creates a new ChaCha20-Poly1305 encryption service. The key is hashed with SHA-256 to produce a consistent 32-byte key.
type Encryptor ¶
type Encryptor interface {
Encrypt(plaintext string) (string, error)
Decrypt(ciphertext string) (string, error)
}
Encryptor defines the interface for symmetric encryption and decryption. Projects choose which implementation to use based on their requirements.
type Option ¶
type Option func(*options)
Option configures the encryption service.
func WithAlgorithm ¶
WithAlgorithm selects the encryption algorithm (default: AES-256-GCM).
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service handles encryption/decryption of sensitive data using AES-256-GCM.
func NewService ¶
NewService creates a new encryption service with the given key. The key is hashed with SHA-256 to produce a consistent 32-byte AES key.