crypto

package
v0.0.0-...-343c8d2 Latest Latest
Warning

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

Go to latest
Published: May 7, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ExportVersion is the current export format version
	ExportVersion = "1"
	// Algorithm specifies the encryption algorithm used
	Algorithm = "aes-256-gcm"
	// SaltLength is the length of the salt in bytes
	SaltLength = 16
	// KeyLength is the length of the derived key in bytes (256 bits)
	KeyLength = 32
	// PBKDF2Iterations is the number of iterations for PBKDF2
	PBKDF2Iterations = 100000
	// MinPasswordLength is the minimum required password length
	MinPasswordLength = 8
)
View Source
const EncryptedPrefix = "ENC:"

EncryptedPrefix is the prefix used to identify encrypted values

Variables

This section is empty.

Functions

func ExportVersionVersion

func ExportVersionVersion() string

ExportVersionVersion returns the current export version

func GetOrCreateKeyFile

func GetOrCreateKeyFile() (string, error)

GetOrCreateKeyFile gets or creates a key file for additional security (optional)

func IsEncrypted

func IsEncrypted(value string) bool

IsEncrypted checks if a string appears to be encrypted Uses the ENC: prefix for reliable detection

func ValidatePassword

func ValidatePassword(password string) error

ValidatePassword validates that the password meets security requirements

Types

type EncryptedExport

type EncryptedExport struct {
	Version   string `json:"version"`
	Algorithm string `json:"algorithm"`
	Salt      string `json:"salt"`
	Nonce     string `json:"nonce"`
	Data      string `json:"data"`
}

EncryptedExport represents the encrypted export format

type ExportConfig

type ExportConfig struct {
	Alias     string   `json:"alias"`
	Provider  string   `json:"provider"`
	APIKey    string   `json:"api_key"`
	AuthToken string   `json:"auth_token"`
	BaseURL   string   `json:"base_url"`
	Model     string   `json:"model"`
	Models    []string `json:"models,omitempty"`
}

ExportConfig represents a single exported configuration

func NewExportConfig

func NewExportConfig(alias, provider, apiKey, authToken, baseURL, model string, models []string) ExportConfig

NewExportConfig creates a new ExportConfig from API config values

type ExportFormat

type ExportFormat struct {
	Version   string         `json:"version"`
	Timestamp int64          `json:"timestamp"`
	Configs   []ExportConfig `json:"configs"`
}

ExportFormat represents the unencrypted export format

func NewExportFormat

func NewExportFormat(configs []ExportConfig) *ExportFormat

NewExportFormat creates a new ExportFormat from configurations

type KeyManager

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

KeyManager handles encryption and decryption of API keys

func NewKeyManager

func NewKeyManager() (*KeyManager, error)

NewKeyManager creates a new KeyManager with a derived key

func (*KeyManager) Decrypt

func (km *KeyManager) Decrypt(ciphertext string) (string, error)

Decrypt decrypts the encrypted API key

func (*KeyManager) Encrypt

func (km *KeyManager) Encrypt(plaintext string) (string, error)

Encrypt encrypts the plaintext API key

type PasswordManager

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

PasswordManager handles password-based encryption and decryption

func NewPasswordManager

func NewPasswordManager(password string) *PasswordManager

NewPasswordManager creates a new PasswordManager with the given password

func (*PasswordManager) Decrypt

func (pm *PasswordManager) Decrypt(encoded string) (*ExportFormat, error)

Decrypt decrypts a base64-encoded encrypted string and returns an ExportFormat

func (*PasswordManager) Encrypt

func (pm *PasswordManager) Encrypt(export *ExportFormat) (string, error)

Encrypt encrypts an ExportFormat and returns a base64-encoded encrypted string

Jump to

Keyboard shortcuts

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