crypto

package
v0.5.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 4, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCiphertext = errors.New("invalid ciphertext")
	ErrInvalidKey        = errors.New("invalid encryption key")
)

Functions

func DecodeKey

func DecodeKey(encoded string) ([]byte, error)

DecodeKey decodes a base64-encoded key

func EncodeKey

func EncodeKey(key []byte) string

EncodeKey encodes a key to base64 for storage

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey generates a random 32-byte encryption key

Types

type Encryptor

type Encryptor struct {
	// contains filtered or unexported fields
}

Encryptor provides encryption/decryption operations using XChaCha20-Poly1305

func NewEncryptor

func NewEncryptor(key []byte) (*Encryptor, error)

NewEncryptor creates a new encryptor with the given 32-byte key

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(ciphertext string) ([]byte, error)

Decrypt decrypts base64-encoded ciphertext (with nonce prepended)

func (*Encryptor) DecryptMap

func (e *Encryptor) DecryptMap(data map[string]interface{}, sensitiveKeys map[string]bool) error

DecryptMap decrypts all string values in a map that match the given keys

func (*Encryptor) DecryptString

func (e *Encryptor) DecryptString(ciphertext string) (string, error)

DecryptString decrypts a base64-encoded ciphertext to a string

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext []byte) (string, error)

Encrypt encrypts plaintext and returns base64-encoded ciphertext with nonce prepended

func (*Encryptor) EncryptMap

func (e *Encryptor) EncryptMap(data map[string]interface{}, sensitiveKeys map[string]bool) error

EncryptMap encrypts all string values in a map that match the given keys

func (*Encryptor) EncryptString

func (e *Encryptor) EncryptString(plaintext string) (string, error)

EncryptString encrypts a string value

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL