box

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Dec 18, 2025 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

Variables

View Source
var (
	ErrInvalidKeySize = errors.New("key must be exactly 32 bytes")
	ErrUnwrapFailed   = errors.New("unwrapped data is not a valid key")
)

Functions

func Decrypt

func Decrypt(ciphertext, nonce []byte, senderPub *ecdh.PublicKey, recipientPriv *ecdh.PrivateKey) ([]byte, error)

Decrypt decrypts data using recipient's private key and sender's public key pair.

func Encrypt

func Encrypt(plaintext []byte, senderPriv *ecdh.PrivateKey, recipientPub *ecdh.PublicKey) ([]byte, []byte, error)

Encrypt encrypts data using sernder's private key and recipient's public key pair.

func LoadPublicKey

func LoadPublicKey(pubBytes []byte) (*ecdh.PublicKey, error)

LoadPublicKey converts raw bytes back into a Public Key object.

func Seal

func Seal(plaintext []byte, recipientPub *ecdh.PublicKey) ([]byte, []byte, error)

Seal encrypts a message anonymously. It generates an temporary key pair, so the sender does not need an identity.

Output Structure: [EphemeralPublicKey (32 bytes)] + [VaultBlob (Nonce + Ciphertext)]

func Unseal

func Unseal(encBlob, nonce []byte, recipientPriv *ecdh.PrivateKey) ([]byte, error)

Unseal decrypts an anonymously encrypted message. It extracts the temprorary public key from the header and uses it to derive the decryption key.

func UnwrapKey

func UnwrapKey(wrappedBlob, nonce []byte, myPriv *ecdh.PrivateKey) ([]byte, error)

UnwrapKey decrypts a wrapped key using your private key.

func WrapKey

func WrapKey(keyToShare []byte, recipientPub *ecdh.PublicKey) ([]byte, []byte, error)

WrapKey encrypts a symmetric key for a recipient.

Types

type KeyPair

type KeyPair struct {
	Public  *ecdh.PublicKey
	Private *ecdh.PrivateKey
}

func GenerateKeyPair

func GenerateKeyPair() (*KeyPair, error)

GenerateKeyPair creates a fresh X25519 identity for encryption.

func LoadPrivateKey

func LoadPrivateKey(privBytes []byte) (*KeyPair, error)

LoadPrivateKey converts raw bytes into a usable Key Pair object.

func (*KeyPair) Bytes

func (k *KeyPair) Bytes() ([]byte, []byte)

Bytes returns the raw 32-byte keys.

Jump to

Keyboard shortcuts

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