Documentation
¶
Overview ¶
Package privacy provides cryptographically secure privacy-preserving hashing utilities for protecting sensitive user data while maintaining analytical capabilities.
Index ¶
- func GenerateMasterKey() ([]byte, error)
- func GenerateMasterKeyBase64() (string, error)
- type ConfigLoader
- func (cl *ConfigLoader) GetEnvironmentDocumentation() string
- func (cl *ConfigLoader) LoadFromEnvironment() (*HashingConfig, error)
- func (cl *ConfigLoader) LoadHasherFromEnvironment() (*Hasher, error)
- func (cl *ConfigLoader) SetupFromEnvironmentOrGenerate() (*Hasher, error)
- func (cl *ConfigLoader) ValidateEnvironmentVariables() error
- type DataType
- type Hasher
- func (ph *Hasher) GetConfig() *HashingConfig
- func (ph *Hasher) Hash(data string, dataType DataType) (string, error)
- func (ph *Hasher) HashEmail(email string) (string, error)
- func (ph *Hasher) HashIP(ipAddress string) (string, error)
- func (ph *Hasher) HashPII(pii string) (string, error)
- func (ph *Hasher) HashUsername(username string) (string, error)
- func (ph *Hasher) UpdateConfig(config *HashingConfig) error
- func (ph *Hasher) VerifyHash(originalData, hash string, dataType DataType) (bool, error)
- type HashingConfig
- type Level
- type PresetConfigurations
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GenerateMasterKey ¶
GenerateMasterKey generates a cryptographically secure master key
func GenerateMasterKeyBase64 ¶
GenerateMasterKeyBase64 generates a master key and returns it as base64
Types ¶
type ConfigLoader ¶
type ConfigLoader struct {
// contains filtered or unexported fields
}
ConfigLoader handles loading privacy configuration from environment variables
func NewConfigLoader ¶
func NewConfigLoader(envPrefix string) *ConfigLoader
NewConfigLoader creates a new configuration loader with optional environment prefix
func (*ConfigLoader) GetEnvironmentDocumentation ¶
func (cl *ConfigLoader) GetEnvironmentDocumentation() string
GetEnvironmentDocumentation returns documentation for all privacy environment variables
func (*ConfigLoader) LoadFromEnvironment ¶
func (cl *ConfigLoader) LoadFromEnvironment() (*HashingConfig, error)
LoadFromEnvironment loads privacy hashing configuration from environment variables Deprecated: Use LoadFromConfig() instead for centralized configuration
func (*ConfigLoader) LoadHasherFromEnvironment ¶
func (cl *ConfigLoader) LoadHasherFromEnvironment() (*Hasher, error)
LoadHasherFromEnvironment creates a Hasher from environment variables
func (*ConfigLoader) SetupFromEnvironmentOrGenerate ¶
func (cl *ConfigLoader) SetupFromEnvironmentOrGenerate() (*Hasher, error)
SetupFromEnvironmentOrGenerate sets up privacy hashing from environment or generates new keys
func (*ConfigLoader) ValidateEnvironmentVariables ¶
func (cl *ConfigLoader) ValidateEnvironmentVariables() error
ValidateEnvironmentVariables validates that required environment variables are set
type DataType ¶
type DataType string
DataType represents the type of data being hashed for different privacy strategies
const ( // DataTypeIP represents IP address data DataTypeIP DataType = "ip" // DataTypeEmail represents email address data DataTypeEmail DataType = "email" // DataTypeUsername represents username data DataTypeUsername DataType = "username" // DataTypePII represents personally identifiable information DataTypePII DataType = "pii" // DataTypeGeneric represents generic sensitive data DataTypeGeneric DataType = "generic" )
type Hasher ¶
type Hasher struct {
// contains filtered or unexported fields
}
Hasher provides cryptographically secure privacy hashing
func NewHasher ¶
func NewHasher(config *HashingConfig) (*Hasher, error)
NewHasher creates a new privacy hasher with the given configuration
func NewHasherFromMasterKey ¶
NewHasherFromMasterKey creates a hasher with default config and the given master key
func (*Hasher) GetConfig ¶
func (ph *Hasher) GetConfig() *HashingConfig
GetConfig returns a copy of the current configuration (without the master key for security)
func (*Hasher) HashEmail ¶
HashEmail provides email privacy hashing with optional domain preservation
func (*Hasher) HashIP ¶
HashIP provides IP address privacy hashing with optional subnet preservation
func (*Hasher) HashUsername ¶
HashUsername provides username privacy hashing
func (*Hasher) UpdateConfig ¶
func (ph *Hasher) UpdateConfig(config *HashingConfig) error
UpdateConfig updates the hasher configuration
type HashingConfig ¶
type HashingConfig struct {
// Master key for HMAC (must be kept secret)
MasterKey []byte
// Privacy levels for different data types
IPLevel Level
EmailLevel Level
UsernameLevel Level
PIILevel Level
GenericLevel Level
// Key rotation settings
KeyRotationEnabled bool
KeyRotationInterval time.Duration
// Performance settings
Argon2Memory uint32 // Memory usage in KB
Argon2Time uint32 // Number of iterations
Argon2Threads uint8 // Number of threads
Argon2KeyLen uint32 // Length of derived key
}
HashingConfig defines configuration for privacy hashing
func DefaultConfig ¶
func DefaultConfig() *HashingConfig
DefaultConfig returns a secure default configuration
func LoadFromConfig ¶
func LoadFromConfig() (*HashingConfig, error)
LoadFromConfig loads privacy hashing configuration from centralized config This is the modern approach - use this instead of LoadFromEnvironment
type PresetConfigurations ¶
type PresetConfigurations struct{}
PresetConfigurations provides common preset configurations
func (*PresetConfigurations) GetComplianceConfig ¶
func (pc *PresetConfigurations) GetComplianceConfig(masterKey []byte) (*HashingConfig, error)
GetComplianceConfig returns a configuration suitable for strict compliance requirements
func (*PresetConfigurations) GetDevelopmentConfig ¶
func (pc *PresetConfigurations) GetDevelopmentConfig() (*HashingConfig, error)
GetDevelopmentConfig returns a configuration suitable for development
func (*PresetConfigurations) GetProductionConfig ¶
func (pc *PresetConfigurations) GetProductionConfig(masterKey []byte) (*HashingConfig, error)
GetProductionConfig returns a configuration suitable for production with maximum security