Documentation
¶
Overview ¶
Package symmetric provides simple symmetric encryption and decryption using AES-GCM with a key derived from a passphrase via SHA-256.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EncryptedData ¶
type EncryptedData struct {
Nonce []byte // Nonce used for encryption (e.g., IV or GCM nonce)
Ciphertext []byte // The encrypted data
}
EncryptedData represents data encrypted with a symmetric cipher. It contains the nonce (initialization vector) and the ciphertext. Both fields are stored as byte slices.
func (*EncryptedData) MarshalJSON ¶
func (e *EncryptedData) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface for EncryptedData. It encodes the Nonce and Ciphertext fields as base64 strings for safe JSON transport.
func (*EncryptedData) UnmarshalJSON ¶
func (e *EncryptedData) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface for EncryptedData. It decodes base64-encoded Nonce and Ciphertext fields from JSON into byte slices.
type SymmetricCrypter ¶ added in v0.1.2
type SymmetricCrypter struct {
// contains filtered or unexported fields
}
SymmetricCrypter manages symmetric encryption and decryption operations using AES-GCM. The encryption key is derived from a passphrase.
func NewSymmetricCrypter ¶ added in v0.1.2
func NewSymmetricCrypter(key string) *SymmetricCrypter
NewSymmetricCrypter creates a new SymmetricCrypter instance. The provided key string is hashed using SHA-256 to produce a 32-byte key.
func (*SymmetricCrypter) Decrypt ¶ added in v0.1.2
func (c *SymmetricCrypter) Decrypt(data EncryptedData) ([]byte, error)
Decrypt decrypts the provided EncryptedData using AES-GCM. It returns the original plaintext if decryption is successful.
func (*SymmetricCrypter) Encrypt ¶ added in v0.1.2
func (c *SymmetricCrypter) Encrypt(plaintext []byte) (*EncryptedData, error)
Encrypt encrypts the given plaintext using AES-GCM. It returns an EncryptedData struct containing the nonce and ciphertext.