encryption

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidKey        = errors.New("encryption key must be 32 bytes")
	ErrInvalidCiphertext = errors.New("invalid ciphertext format")
	ErrDecryptionFailed  = errors.New("decryption failed")
)

Functions

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey generates a random 32-byte encryption key suitable for AES-256 This is a helper function for initial setup, not for production use

func GenerateKeyBase64

func GenerateKeyBase64() (string, error)

GenerateKeyBase64 generates a random 32-byte key and returns it base64-encoded

Types

type Service

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

Service provides AES-256-GCM encryption/decryption for sensitive data

func NewService

func NewService(key []byte) (*Service, error)

NewService creates a new encryption service with the provided 32-byte key

func NewServiceFromBase64

func NewServiceFromBase64(encodedKey string) (*Service, error)

NewServiceFromBase64 creates a new encryption service from a base64-encoded key

func (*Service) Decrypt

func (s *Service) Decrypt(encodedCiphertext string) (string, error)

Decrypt decrypts base64-encoded ciphertext using AES-256-GCM

func (*Service) Encrypt

func (s *Service) Encrypt(plaintext string) (string, error)

Encrypt encrypts plaintext using AES-256-GCM and returns base64-encoded ciphertext Format: base64(nonce + ciphertext + tag)

Jump to

Keyboard shortcuts

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