crypto

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Streaming parameters matching web app
	StreamMagic      = "PHNT"
	StreamVersion    = 1
	StreamChunkSize  = 64 * 1024 // 64KB chunks
	StreamNonceSize  = 12
	StreamTagSize    = 16
	StreamHeaderSize = 28 // 4 magic + 4 version + 4 chunk_size + 4 total_chunks + 12 base_nonce
)

Variables

This section is empty.

Functions

func Decrypt

func Decrypt(data, key []byte) ([]byte, error)

Decrypt decrypts data encrypted with AES-256-GCM. Expects [12-byte IV][ciphertext + GCM auth tag] format.

func DecryptAuto added in v0.2.0

func DecryptAuto(ciphertext, key []byte) ([]byte, error)

DecryptAuto auto-detects format and decrypts (streaming or legacy)

func DecryptFile

func DecryptFile(ciphertext []byte, key []byte) ([]byte, error)

DecryptFile decrypts ciphertext and returns the original file contents.

func DecryptStream added in v0.2.0

func DecryptStream(ciphertext, key []byte) ([]byte, error)

DecryptStream decrypts streaming format data

func Encrypt

func Encrypt(plaintext, key []byte) ([]byte, error)

Encrypt encrypts data with AES-256-GCM. Returns [12-byte IV][ciphertext + GCM auth tag], matching the web app format.

func EncryptFile

func EncryptFile(plaintext []byte, key []byte) ([]byte, error)

EncryptFile reads a file's contents, encrypts it, and returns the ciphertext.

func EncryptStream added in v0.2.0

func EncryptStream(plaintext, key []byte) ([]byte, error)

EncryptStream encrypts data using streaming AES-256-GCM with STREAM construction

func ExportKey

func ExportKey(key []byte) string

ExportKey encodes a raw key as base64url (no padding), matching the web app format.

func GenerateKey

func GenerateKey() ([]byte, error)

GenerateKey creates a new 256-bit AES key.

func ImportKey

func ImportKey(encoded string) ([]byte, error)

ImportKey decodes a base64url key string back to raw bytes.

Types

type StreamHeader added in v0.2.0

type StreamHeader struct {
	Magic       [4]byte
	Version     uint32
	ChunkSize   uint32
	TotalChunks uint32
	BaseNonce   [StreamNonceSize]byte
}

StreamHeader represents the streaming encryption header

Jump to

Keyboard shortcuts

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