crypto

package
v0.11.0 Latest Latest
Warning

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

Go to latest
Published: Jul 18, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EncryptionHeader marks encrypted files
	EncryptionHeader = "TAKO_ENCRYPTED_V1:"
)
View Source
const (
	// PassphraseHeader marks passphrase-encrypted data
	PassphraseHeader = "TAKO_PASSPHRASE_V1:"
)

Variables

This section is empty.

Functions

func DecryptWithPassphrase added in v0.2.6

func DecryptWithPassphrase(data []byte, passphrase string) ([]byte, error)

DecryptWithPassphrase decrypts data that was encrypted with EncryptWithPassphrase

func EncryptWithPassphrase added in v0.2.6

func EncryptWithPassphrase(plaintext []byte, passphrase string) ([]byte, error)

EncryptWithPassphrase encrypts plaintext using a passphrase with Argon2id KDF + AES-256-GCM

func GetDefaultKeyPath

func GetDefaultKeyPath() string

GetDefaultKeyPath returns the default encryption key path

func GetProjectKeyPath

func GetProjectKeyPath(projectDir string) string

GetProjectKeyPath returns the project-specific encryption key path

func IsEncrypted

func IsEncrypted(data []byte) bool

IsEncrypted checks if data has the encryption header

func IsFileEncrypted

func IsFileEncrypted(filePath string) (bool, error)

IsFileEncrypted checks if a file is encrypted

func IsPassphraseEncrypted added in v0.2.6

func IsPassphraseEncrypted(data []byte) bool

IsPassphraseEncrypted checks if data has the passphrase encryption header

Types

type EncryptedData

type EncryptedData struct {
	Salt       string `json:"salt"`       // Base64 encoded salt
	Nonce      string `json:"nonce"`      // Base64 encoded nonce
	Ciphertext string `json:"ciphertext"` // Base64 encoded encrypted data
}

EncryptedData represents the structure of encrypted content

type Encryptor

type Encryptor struct {
	// contains filtered or unexported fields
}

Encryptor handles encryption/decryption operations

func NewEncryptor

func NewEncryptor(passphrase string) *Encryptor

NewEncryptor creates a new Encryptor with the given passphrase The passphrase is derived into a secure key using PBKDF2

func NewEncryptorFromKeyFile

func NewEncryptorFromKeyFile(keyPath string) (*Encryptor, error)

NewEncryptorFromKeyFile creates an Encryptor using a key file If the key file doesn't exist, it generates a new random key

func (*Encryptor) Decrypt

func (e *Encryptor) Decrypt(data []byte) ([]byte, error)

Decrypt decrypts data that was encrypted with Encrypt

func (*Encryptor) DecryptFile

func (e *Encryptor) DecryptFile(filePath string) error

DecryptFile decrypts a file in place

func (*Encryptor) DecryptString

func (e *Encryptor) DecryptString(encrypted string) (string, error)

DecryptString decrypts a string that was encrypted with EncryptString

func (*Encryptor) Encrypt

func (e *Encryptor) Encrypt(plaintext []byte) ([]byte, error)

Encrypt encrypts plaintext data and returns encrypted data with header

func (*Encryptor) EncryptFile

func (e *Encryptor) EncryptFile(filePath string) error

EncryptFile encrypts a file in place

func (*Encryptor) EncryptString

func (e *Encryptor) EncryptString(plaintext string) (string, error)

EncryptString encrypts a string and returns base64-encoded result

func (*Encryptor) ReadEncryptedFile

func (e *Encryptor) ReadEncryptedFile(filePath string) ([]byte, error)

ReadEncryptedFile reads and decrypts a file, returning plaintext If file is not encrypted, returns contents as-is

func (*Encryptor) WriteEncryptedFile

func (e *Encryptor) WriteEncryptedFile(filePath string, data []byte, perm os.FileMode) error

WriteEncryptedFile encrypts and writes data to a file

type PassphraseEncryptedData added in v0.2.6

type PassphraseEncryptedData struct {
	Salt       string `json:"salt"`       // Base64 encoded salt
	Nonce      string `json:"nonce"`      // Base64 encoded nonce
	Ciphertext string `json:"ciphertext"` // Base64 encoded encrypted data
	Time       uint32 `json:"time"`       // Argon2id time parameter
	Memory     uint32 `json:"memory"`     // Argon2id memory parameter (KiB)
	Threads    uint8  `json:"threads"`    // Argon2id threads parameter
}

PassphraseEncryptedData represents passphrase-encrypted content

Jump to

Keyboard shortcuts

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