sealedbox

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Overview

Package sealedbox implements the Kryptic P-256 ECDH sealed box: encrypt a value to a recipient's public key so only the holder of the matching private key can open it. This is the asymmetric layer the blind store uses to deliver the org key; the wire format and derivation are locked by interop-vectors/sealed-box-p256.json (canonical copies live in all three encryption repositories).

Construction (ECIES): fresh ephemeral P-256 key pair per message, ECDH against the recipient public key, HKDF-SHA256 expanded to a 32-byte AES key and a 12-byte nonce (derived, not random: the per-message key makes it safe and the seal reproducible), then AES-256-GCM. No custom primitives.

Index

Constants

View Source
const (
	// FormatVersion is the sealed-box wire format version this package produces.
	FormatVersion = 1

	// PublicKeySize is the uncompressed SEC1 P-256 point: 0x04 || X(32) || Y(32).
	PublicKeySize = 65

	// PrivateKeySize is the P-256 scalar, big-endian.
	PrivateKeySize = 32
)

Variables

This section is empty.

Functions

func Open

func Open(recipient KeyPair, box SealedKey) ([]byte, error)

Open decrypts a sealed box with the recipient key pair.

Types

type KeyPair

type KeyPair struct {
	Public  []byte // 65-byte uncompressed SEC1 point
	Private []byte // 32-byte big-endian scalar
}

KeyPair is a P-256 key pair in the portable encodings shared with the C# and WebCrypto implementations.

func GenerateKeyPair

func GenerateKeyPair() (KeyPair, error)

GenerateKeyPair creates a fresh P-256 key pair.

type SealedKey

type SealedKey struct {
	RecipientKeyID     string
	EphemeralPublicKey []byte
	Nonce              []byte
	CiphertextWithTag  []byte
}

SealedKey is a parsed sealed box.

func Parse

func Parse(value string) (SealedKey, error)

Parse parses the canonical wire form.

func Seal

func Seal(recipientPublicKey []byte, recipientKeyID string, plaintext []byte) (SealedKey, error)

Seal encrypts plaintext to the recipient public key with a fresh ephemeral key.

func (SealedKey) Serialize

func (s SealedKey) Serialize() string

Serialize renders the canonical wire form: sbx.v1.<recipientKeyId>.<ephemeralPub>.<nonce>.<ciphertext+tag> (base64url, no padding).

Jump to

Keyboard shortcuts

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