crypto

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: Unlicense Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodePublicKey

func DecodePublicKey(data []byte) (*[32]byte, error)

DecodePublicKey decodes a base64-encoded public key.

func DecodePublicKeyString

func DecodePublicKeyString(s string) (*[32]byte, error)

DecodePublicKeyString decodes a base64-encoded public key string.

func DecryptPrivateKey

func DecryptPrivateKey(data []byte, passphrase string) (*[32]byte, error)

DecryptPrivateKey decrypts a private key blob produced by EncryptPrivateKey.

func EncodePublicKey

func EncodePublicKey(pub *[32]byte) []byte

EncodePublicKey encodes a public key to base64 bytes for storage.

func EncodePublicKeyString

func EncodePublicKeyString(pub *[32]byte) string

EncodePublicKeyString encodes a public key to a base64 string.

func EncryptPrivateKey

func EncryptPrivateKey(privKey *[32]byte, passphrase string) ([]byte, error)

EncryptPrivateKey encrypts a private key with a passphrase using Argon2id + NaCl secretbox. Returns: salt (16 bytes) || nonce (24 bytes) || secretbox ciphertext

func GenerateKeyPair

func GenerateKeyPair() (priv *[32]byte, pub *[32]byte, err error)

GenerateKeyPair creates a new X25519 keypair.

func HasLocalKeys

func HasLocalKeys() bool

HasLocalKeys returns true if local keys exist.

func LoadPrivateKey

func LoadPrivateKey() (*[32]byte, error)

LoadPrivateKey loads the private key from local storage.

func LoadPublicKey

func LoadPublicKey() (*[32]byte, error)

LoadPublicKey loads the public key from local storage.

func PromptPassphrase

func PromptPassphrase(create bool) (string, error)

PromptPassphrase prompts the user for a passphrase via the terminal. If create is true, asks for confirmation and validates the passphrase.

func SaveKeyPair

func SaveKeyPair(priv *[32]byte, pub *[32]byte) error

SaveKeyPair saves the keypair to ~/.config/vaultenv/keys/

func ValidatePassphrase

func ValidatePassphrase(passphrase string) error

ValidatePassphrase checks that a passphrase meets the minimum requirements: - at least 12 characters - at least one uppercase letter - at least one digit - at least one special character

Types

type Engine

type Engine interface {
	EncryptForRecipients(plaintext []byte, recipients map[string][32]byte) (ciphertext []byte, envelopes map[string]vault.Envelope, err error)
	DecryptWithEnvelope(ciphertext []byte, envelope vault.Envelope, privateKey *[32]byte) (plaintext []byte, err error)
	WrapKeyForRecipient(symKey *[32]byte, recipientPub *[32]byte) (vault.Envelope, error)
	UnwrapKey(envelope vault.Envelope, privateKey *[32]byte) (*[32]byte, error)
}

Engine defines the encryption/decryption interface. Implementations can use different crypto backends (NaCl, age, KMS, etc.).

type NaClEngine

type NaClEngine struct{}

func NewNaClEngine

func NewNaClEngine() *NaClEngine

func (*NaClEngine) DecryptWithEnvelope

func (n *NaClEngine) DecryptWithEnvelope(ciphertext []byte, envelope vault.Envelope, privateKey *[32]byte) ([]byte, error)

func (*NaClEngine) EncryptForRecipients

func (n *NaClEngine) EncryptForRecipients(plaintext []byte, recipients map[string][32]byte) ([]byte, map[string]vault.Envelope, error)

func (*NaClEngine) UnwrapKey

func (n *NaClEngine) UnwrapKey(envelope vault.Envelope, privateKey *[32]byte) (*[32]byte, error)

func (*NaClEngine) WrapKeyForRecipient

func (n *NaClEngine) WrapKeyForRecipient(symKey *[32]byte, recipientPub *[32]byte) (vault.Envelope, error)

Jump to

Keyboard shortcuts

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