crypto

package
v0.0.1-dev.12 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LoadOrGenerateKEK

func LoadOrGenerateKEK(opts KEKOptions) ([]byte, error)

LoadOrGenerateKEK loads a 32-byte KEK according to options. File/env values are expected to be base64-encoded 32 bytes. If Source is generated or GenerateIfMissing is true, a new random key will be produced and, if FilePath is set, persisted with permissions 0600.

func RandomBytes

func RandomBytes(n int) ([]byte, error)

RandomBytes returns n cryptographically-secure random bytes.

Types

type AEADCipher

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

AEADCipher provides authenticated encryption with associated data (AEAD) using AES-256-GCM.

func NewAEADCipher

func NewAEADCipher(key []byte) (*AEADCipher, error)

NewAEADCipher creates a new AEAD cipher with the provided 32-byte key.

func (*AEADCipher) Decrypt

func (a *AEADCipher) Decrypt(data, aad []byte) ([]byte, error)

Decrypt decrypts data produced by Encrypt. Input must be nonce||ciphertext.

func (*AEADCipher) Encrypt

func (a *AEADCipher) Encrypt(plaintext, aad []byte) ([]byte, error)

Encrypt encrypts plaintext with optional associated data (aad). It returns nonce||ciphertext, where nonce is 12 random bytes.

func (*AEADCipher) Zeroize

func (a *AEADCipher) Zeroize()

Zeroize attempts to clear key material from memory.

type KEKOptions

type KEKOptions struct {
	Source            KEKSource
	FilePath          string
	EnvVar            string // e.g., RUNE_MASTER_KEY
	GenerateIfMissing bool
}

KEKOptions holds configuration for loading the KEK

type KEKSource

type KEKSource string

KEKSource defines how to load the master key (KEK)

const (
	KEKSourceFile      KEKSource = "file"
	KEKSourceEnv       KEKSource = "env"
	KEKSourceGenerated KEKSource = "generated"
)

Jump to

Keyboard shortcuts

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