crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoKey          = errors.New("encryption key not configured")
	ErrDecryptFailed  = errors.New("decryption failed")
	ErrInvalidPayload = errors.New("invalid encrypted payload")
)

Functions

func Decrypt

func Decrypt(ciphertext string) (string, error)

Decrypt reverses Encrypt. Values without the "enc:" prefix are returned as-is (legacy unencrypted data).

func DecryptSettingValue

func DecryptSettingValue(key string, value string) (string, error)

DecryptSettingValue decrypts the value if it carries the "enc:" prefix. Non-sensitive keys, empty values, and legacy plaintext pass through unchanged.

func Encrypt

func Encrypt(plaintext string) (string, error)

Encrypt returns the AES-GCM ciphertext as a base64 string prefixed with "enc:". If plaintext is empty or the key was never initialized, the plaintext is returned unchanged so callers can treat empty and legacy values transparently.

func EncryptSettingValue

func EncryptSettingValue(key string, value string) (string, error)

EncryptSettingValue encrypts the value if the key is in the sensitive list and the encryption key has been initialised. Non-sensitive keys and empty values pass through unchanged.

func Init

func Init(rawSecret string)

Init derives a 256-bit AES key from the raw secret and stores it for the process lifetime. Call once at startup; subsequent calls are no-ops.

func IsEncrypted

func IsEncrypted(s string) bool

IsEncrypted reports whether the value carries the "enc:" prefix.

func IsSensitiveSetting

func IsSensitiveSetting(key string) bool

IsSensitiveSetting reports whether the given setting key should be encrypted.

Types

This section is empty.

Jump to

Keyboard shortcuts

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