crypto

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 1, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package crypto provides AES-GCM-256 encryption primitives and master-key helpers for Relay's stored-secret subsystem. All functions are pure; the package has no state.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(masterKey, ciphertext, nonce []byte) ([]byte, error)

Decrypt decrypts ciphertext (with GCM auth tag) using masterKey and nonce. Returns an error if the tag is invalid or inputs are malformed; never panics.

func Encrypt

func Encrypt(masterKey, plaintext []byte) (ciphertext, nonce []byte, err error)

Encrypt encrypts plaintext with AES-GCM-256 using masterKey. masterKey must be exactly 32 bytes. A fresh 12-byte nonce is read from crypto/rand on each call. Returns ciphertext (with GCM auth tag appended by gcm.Seal) and nonce separately; callers store them in distinct DB columns.

func GenerateMasterKey

func GenerateMasterKey() (string, error)

GenerateMasterKey generates 32 random bytes and returns them as a base64.StdEncoding string suitable for use as RELAY_MASTER_KEY.

func ParseMasterKey

func ParseMasterKey(raw string) ([]byte, error)

ParseMasterKey base64-decodes (StdEncoding) raw and validates the result is exactly 32 bytes. Returns the raw key bytes or a structured error.

Types

This section is empty.

Jump to

Keyboard shortcuts

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