crypto

package
v1.0.0-rc07 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 19 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package crypto provides cryptographic utilities for key generation, validation, and management.

This package extracts common cryptographic functionality from the SOPS module to provide reusable, testable components for managing Age keys and other cryptographic operations.

Key interfaces:

  • KeyGenerator: Generates cryptographic keys
  • KeyValidator: Validates key formats and security
  • KeyManager: Comprehensive key management operations

The package follows interface-based design principles to enable easy testing and dependency injection throughout the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsPlaceholderKey

func IsPlaceholderKey(key string) bool

IsPlaceholderKey checks if a key is a placeholder

func IsValidAgePrivateKey

func IsValidAgePrivateKey(key string) bool

IsValidAgePrivateKey checks if a string is a valid age private key

func IsValidAgePublicKey

func IsValidAgePublicKey(key string) bool

IsValidAgePublicKey checks if a string is a valid age public key

func ValidateKeyPair

func ValidateKeyPair(privateKey, publicKey string) error

ValidateKeyPair validates that a private and public key pair match

Types

type AgeKeyGenerator

type AgeKeyGenerator struct{}

AgeKeyGenerator implements KeyGenerator for Age keys

func NewAgeKeyGenerator

func NewAgeKeyGenerator() *AgeKeyGenerator

NewAgeKeyGenerator creates a new Age key generator

func (*AgeKeyGenerator) GenerateAgeKey

func (g *AgeKeyGenerator) GenerateAgeKey() (*AgeKeyPair, error)

GenerateAgeKey generates a new age key pair with validation

func (*AgeKeyGenerator) GenerateFallbackKey

func (g *AgeKeyGenerator) GenerateFallbackKey() (*AgeKeyPair, error)

GenerateFallbackKey generates a fallback age key when no key is available

func (*AgeKeyGenerator) GenerateRandomPassword

func (g *AgeKeyGenerator) GenerateRandomPassword(length int) (string, error)

GenerateRandomPassword generates a random password for key encryption

type AgeKeyPair

type AgeKeyPair struct {
	PublicKey  string `json:"public_key"`
	PrivateKey string `json:"private_key"`
	Recipient  string `json:"recipient"`
}

AgeKeyPair represents an age key pair

func GenerateKeyWithTimestamp

func GenerateKeyWithTimestamp(prefix string) (string, *AgeKeyPair, error)

GenerateKeyWithTimestamp generates a key with a timestamp-based name

func ParseAgeKey

func ParseAgeKey(privateKey string) (*AgeKeyPair, error)

ParseAgeKey parses an age private key and returns the key pair

type AgeKeyValidator

type AgeKeyValidator struct{}

AgeKeyValidator implements KeyValidator for Age keys

func NewAgeKeyValidator

func NewAgeKeyValidator() *AgeKeyValidator

NewAgeKeyValidator creates a new Age key validator

func (*AgeKeyValidator) ValidateAgeKey

func (v *AgeKeyValidator) ValidateAgeKey(key string) error

ValidateAgeKey validates an age key format

func (*AgeKeyValidator) ValidateKeyAccess

func (v *AgeKeyValidator) ValidateKeyAccess(keyName string) error

ValidateKeyAccess validates that a key can be used for encryption/decryption This is a placeholder implementation that would need to be implemented by the concrete key manager

func (*AgeKeyValidator) ValidateKeyForProduction

func (v *AgeKeyValidator) ValidateKeyForProduction(key string) error

ValidateKeyForProduction validates that a key is not a placeholder

func (*AgeKeyValidator) ValidatePGPKey

func (v *AgeKeyValidator) ValidatePGPKey(key string) error

ValidatePGPKey validates a PGP key format

type DefaultKeyManager

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

DefaultKeyManager implements KeyManager interface

func NewDefaultKeyManager

func NewDefaultKeyManager(keyDir string) *DefaultKeyManager

NewDefaultKeyManager creates a new default key manager

func (*DefaultKeyManager) BackupKeys

func (m *DefaultKeyManager) BackupKeys(backupPath string) error

BackupKeys creates a backup of all age keys

func (*DefaultKeyManager) CheckAgeInstallation

func (m *DefaultKeyManager) CheckAgeInstallation(ctx context.Context) error

CheckAgeInstallation checks if age is properly installed

func (*DefaultKeyManager) DeleteAgeKey

func (m *DefaultKeyManager) DeleteAgeKey(keyName string) error

DeleteAgeKey deletes an age key pair

func (*DefaultKeyManager) ExportAgeKey

func (m *DefaultKeyManager) ExportAgeKey(keyName string) (*AgeKeyPair, error)

ExportAgeKey exports an age key pair

func (*DefaultKeyManager) GenerateAgeKey

func (m *DefaultKeyManager) GenerateAgeKey() (*AgeKeyPair, error)

GenerateAgeKey generates a new age key pair with validation

func (*DefaultKeyManager) GenerateFallbackKey

func (m *DefaultKeyManager) GenerateFallbackKey() (*AgeKeyPair, error)

GenerateFallbackKey generates a fallback age key when no key is available

func (*DefaultKeyManager) GenerateKeyForCluster

func (m *DefaultKeyManager) GenerateKeyForCluster(clusterName string) (*AgeKeyPair, error)

GenerateKeyForCluster generates and saves an age key for a specific cluster

func (*DefaultKeyManager) GenerateRandomPassword

func (m *DefaultKeyManager) GenerateRandomPassword(length int) (string, error)

GenerateRandomPassword generates a random password for key encryption

func (*DefaultKeyManager) GetKeyInfo

func (m *DefaultKeyManager) GetKeyInfo(keyName string) (*KeyInfo, error)

GetKeyInfo returns information about a key

func (*DefaultKeyManager) ImportAgeKey

func (m *DefaultKeyManager) ImportAgeKey(keyName, privateKey string) (*AgeKeyPair, error)

ImportAgeKey imports an existing age key

func (*DefaultKeyManager) ListAgeKeys

func (m *DefaultKeyManager) ListAgeKeys() ([]string, error)

ListAgeKeys lists all available age keys

func (*DefaultKeyManager) LoadAgeKey

func (m *DefaultKeyManager) LoadAgeKey(keyName string) (*AgeKeyPair, error)

LoadAgeKey loads an age key pair from disk

func (*DefaultKeyManager) RestoreKeys

func (m *DefaultKeyManager) RestoreKeys(backupPath string) error

RestoreKeys restores age keys from a backup

func (*DefaultKeyManager) SaveAgeKey

func (m *DefaultKeyManager) SaveAgeKey(keyPair *AgeKeyPair, keyName string) error

SaveAgeKey saves an age key pair to disk with atomic operations

func (*DefaultKeyManager) SetupAgeEnvironment

func (m *DefaultKeyManager) SetupAgeEnvironment(keyName string) error

SetupAgeEnvironment sets up the age environment for SOPS

func (*DefaultKeyManager) ValidateAgeKey

func (m *DefaultKeyManager) ValidateAgeKey(key string) error

ValidateAgeKey validates an age key format

func (*DefaultKeyManager) ValidateKeyAccess

func (m *DefaultKeyManager) ValidateKeyAccess(keyName string) error

ValidateKeyAccess validates that a key can be used for encryption/decryption

func (*DefaultKeyManager) ValidateKeyForProduction

func (m *DefaultKeyManager) ValidateKeyForProduction(key string) error

ValidateKeyForProduction validates that a key is not a placeholder

func (*DefaultKeyManager) ValidatePGPKey

func (m *DefaultKeyManager) ValidatePGPKey(key string) error

ValidatePGPKey validates a PGP key format

type KeyGenerator

type KeyGenerator interface {
	GenerateAgeKey() (*AgeKeyPair, error)
	GenerateRandomPassword(length int) (string, error)
	GenerateFallbackKey() (*AgeKeyPair, error)
}

KeyGenerator interface for generating cryptographic keys

type KeyInfo

type KeyInfo struct {
	Name      string    `json:"name"`
	PublicKey string    `json:"public_key"`
	CreatedAt time.Time `json:"created_at"`
	KeyType   string    `json:"key_type"`
	FilePath  string    `json:"file_path"`
}

KeyInfo represents information about a key

type KeyManager

type KeyManager interface {
	KeyGenerator
	KeyValidator
	LoadAgeKey(keyName string) (*AgeKeyPair, error)
	SaveAgeKey(keyPair *AgeKeyPair, keyName string) error
	ListAgeKeys() ([]string, error)
	DeleteAgeKey(keyName string) error
	ImportAgeKey(keyName, privateKey string) (*AgeKeyPair, error)
	ExportAgeKey(keyName string) (*AgeKeyPair, error)
	BackupKeys(backupPath string) error
	RestoreKeys(backupPath string) error
	GetKeyInfo(keyName string) (*KeyInfo, error)
	SetupAgeEnvironment(keyName string) error
	GenerateKeyForCluster(clusterName string) (*AgeKeyPair, error)
	CheckAgeInstallation(ctx context.Context) error
}

KeyManager interface for managing cryptographic keys

type KeyValidator

type KeyValidator interface {
	ValidateAgeKey(key string) error
	ValidatePGPKey(key string) error
	ValidateKeyAccess(keyName string) error
	ValidateKeyForProduction(key string) error
}

KeyValidator interface for validating cryptographic keys

type SSHKeyPair

type SSHKeyPair struct {
	PrivateKey []byte
	PublicKey  []byte
	KeyType    string
}

SSHKeyPair represents an SSH key pair

func GenerateSSHKey

func GenerateSSHKey(cipherType string) (*SSHKeyPair, error)

GenerateSSHKey generates a passwordless SSH key pair based on the specified cipher type Supported types: ed25519, rsa, ecdsa The comment parameter is added to the public key in the format: key-data comment

func GenerateSSHKeyWithComment

func GenerateSSHKeyWithComment(cipherType, comment string) (*SSHKeyPair, error)

GenerateSSHKeyWithComment generates a passwordless SSH key pair with a custom comment Supported types: ed25519, rsa, ecdsa The comment parameter is added to the public key in the format: key-data comment

Jump to

Keyboard shortcuts

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