backupcrypt

package
v1.0.39 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package backupcrypt implements the versioned authenticated encrypted backup artifact format (OSS-236). Artifacts are AES-256-GCM in chunked streaming mode so memory stays bounded for large worlds: every 64 KiB chunk is authenticated before it is written, the key ID is bound into the authentication data, and a truncated or tampered artifact always fails closed. The format is self-describing: magic, version and key ID precede the ciphertext so a restore can pick the right key and legacy plaintext archives stay recognizable.

Index

Constants

View Source
const (
	Version = 1
)

Variables

View Source
var (
	// ErrWrongKey reports a key that does not match the artifact's key ID or
	// fails authentication. No plaintext is produced.
	ErrWrongKey = errors.New("backup encryption key does not match the artifact")
	// ErrTampered reports an artifact that failed authentication or framing.
	ErrTampered = errors.New("encrypted backup artifact is corrupt or tampered")
	// ErrBadFormat reports a file that is not this artifact format.
	ErrBadFormat = errors.New("not an encrypted backup artifact")
	// ErrKeyMissing reports that encryption is expected but no key is
	// configured. The explicit disabled-encryption state is "no key".
	ErrKeyMissing = errors.New("backup is encrypted but no encryption key is configured")
)

Functions

func DecryptFile

func DecryptFile(srcPath, dstPath string, key *Key) error

DecryptFile verifies and decrypts srcPath into dstPath under key. Every chunk is authenticated before it is written and the whole artifact must verify, so a wrong key or tampering produces no usable plaintext and never an unauthenticated write.

func EncryptFile

func EncryptFile(srcPath, dstPath string, key *Key) error

EncryptFile writes srcPath to dstPath as a versioned authenticated artifact under key. Streaming and bounded: at most one chunk is held in memory at a time.

func EncryptedKeyID

func EncryptedKeyID(path string) (string, error)

EncryptedKeyID returns the key ID recorded in an artifact header.

func IsEncrypted

func IsEncrypted(path string) (bool, error)

IsEncrypted reports whether the file starts with the artifact magic.

Types

type Key

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

Key is a backup encryption key with its non-secret rotation label.

func ParseKey

func ParseKey(keyID, material string) (*Key, error)

ParseKey decodes key material (base64 or hex, 32 bytes) and attaches the key ID recorded with every artifact. The key material is never logged.

func ResolveKey

func ResolveKey(keyID, material string) (*Key, error)

ResolveKey returns the configured key, or nil when encryption is explicitly disabled (no key material configured).

func (*Key) Fingerprint

func (k *Key) Fingerprint() string

Fingerprint returns a short one-way fingerprint of the key material for operational identification. It never reveals key bytes.

Jump to

Keyboard shortcuts

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