msgcrypto

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 5 Imported by: ? 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

Overview

Package msgcrypto provides the small, reusable encryption primitive used by h8s services. It intentionally knows nothing about NATS subjects, HTTP headers, or proxy policy.

The wire format is NATS nkeys' curve format: "xkv1" || 24-byte random nonce || NaCl box ciphertext. nkeys.Seal generates a fresh nonce for every call and nkeys.Open validates the version, nonce, sender public key, and Poly1305 tag.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidRecipient is returned when a public key is missing or not a
	// valid nkeys curve public key.
	ErrInvalidRecipient = errors.New("msgcrypto: invalid recipient curve public key")
	// ErrInvalidSender is returned when a sender public key is missing or not
	// a valid nkeys curve public key.
	ErrInvalidSender = errors.New("msgcrypto: invalid sender curve public key")
	// ErrDecrypt is returned when a sealed message cannot be opened.
	ErrDecrypt = errors.New("msgcrypto: unable to decrypt message")
)

Functions

func ReadSeedFile

func ReadSeedFile(path string) ([]byte, error)

ReadSeedFile reads and trims an encoded curve seed. It rejects empty files and files with group/world permission bits.

Types

type Key

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

Key is a curve keypair. It is safe for concurrent Seal and Open calls; Wipe must only be called after all users have stopped.

func FromSeed

func FromSeed(seed []byte) (*Key, error)

FromSeed creates a keypair from an encoded curve seed (the "SX..." form returned by nkeys.KeyPair.Seed).

func FromSeedFile

func FromSeedFile(path string) (*Key, error)

FromSeedFile loads an encoded curve seed from path. The file must not be group- or world-readable.

func Generate

func Generate() (*Key, error)

Generate creates a new ephemeral curve keypair.

func (*Key) Open

func (k *Key) Open(data []byte, sender string) ([]byte, error)

Open decrypts data from sender. The sender must be a valid "X..." curve public key. A truncated, tampered, or wrong-sender message returns ErrDecrypt.

func (*Key) PublicKey

func (k *Key) PublicKey() string

PublicKey returns the encoded curve public key (the "X..." form).

func (*Key) Seal

func (k *Key) Seal(data []byte, recipient string) ([]byte, error)

Seal encrypts data to recipient. The recipient must be a valid "X..." curve public key.

func (*Key) Wipe

func (k *Key) Wipe()

Wipe overwrites the private key material on a best-effort basis.

Jump to

Keyboard shortcuts

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