crypto

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EncryptionHeader marks encrypted files
	EncryptionHeader = "TAKO_ENCRYPTED_V1:"
)

Variables

This section is empty.

Functions

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

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

Jump to

Keyboard shortcuts

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