security

package
v4.7.9 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecryptValue added in v4.2.5

func DecryptValue(encryptedValue string, config *EncryptionConfig) (string, error)

DecryptValue enhances decryption with ChaCha20-Poly1305 support

func EncryptData added in v4.5.0

func EncryptData(data interface{}, config *EncryptionConfig) (string, error)

func EncryptValue added in v4.2.5

func EncryptValue(value string, config *EncryptionConfig) (string, error)

EncryptValue 使用指定的配置加密值

Types

type AESEncryptor

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

AESEncryptor 提供AES加密实现

func NewAESEncryptor

func NewAESEncryptor(key []byte) (*AESEncryptor, error)

NewAESEncryptor 创建AES加密器

func (*AESEncryptor) Decrypt

func (e *AESEncryptor) Decrypt(value string) (string, error)

Decrypt 解密数据

func (*AESEncryptor) Encrypt

func (e *AESEncryptor) Encrypt(value string) (string, error)

Encrypt 加密数据

type DBError added in v4.2.5

type DBError struct {
	Code    ErrorCode
	Op      string
	Err     error
	Message string
}

DBError represents a database operation error

func (*DBError) Error added in v4.2.5

func (e *DBError) Error() string

type DataProcessor

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

DataProcessor 数据处理器

func NewDataProcessor

func NewDataProcessor(key []byte) (*DataProcessor, error)

NewDataProcessor 创建数据处理器

func (*DataProcessor) ConfigureField

func (dp *DataProcessor) ConfigureField(field string, config FieldSecurity)

ConfigureField 配置字段安全规则

func (*DataProcessor) ProcessData

func (dp *DataProcessor) ProcessData(data map[string]interface{}) error

ProcessData 处理数据

func (*DataProcessor) UnprocessData

func (dp *DataProcessor) UnprocessData(data map[string]interface{}) error

UnprocessData 还原数据

type DefaultMasker

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

DefaultMasker 提供默认的脱敏实现

func NewDefaultMasker

func NewDefaultMasker() *DefaultMasker

NewDefaultMasker 创建默认的脱敏器

func (*DefaultMasker) AddRule

func (m *DefaultMasker) AddRule(name string, pattern string) error

AddRule 添加自定义脱敏规则

func (*DefaultMasker) Mask

func (m *DefaultMasker) Mask(value string, ruleType string) string

Mask 执行脱敏操作

type EncryptionAlgorithm added in v4.2.5

type EncryptionAlgorithm string

EncryptionAlgorithm defines the encryption algorithm to use

const (
	// AES256 uses AES-256 encryption
	AES256 EncryptionAlgorithm = "AES256"
	// AES192 uses AES-192 encryption
	AES192 EncryptionAlgorithm = "AES192"
	// AES128 uses AES-128 encryption
	AES128 EncryptionAlgorithm = "AES128"
	// ChaCha20Poly1305 uses ChaCha20-Poly1305 encryption
	ChaCha20Poly1305 EncryptionAlgorithm = "ChaCha20Poly1305"
)

type EncryptionConfig added in v4.2.5

type EncryptionConfig struct {
	Algorithm       EncryptionAlgorithm
	KeySource       string
	KeySourceConfig map[string]string
}

EncryptionConfig represents configuration for encryption operations

type Encryptor

type Encryptor interface {
	Encrypt(value string) (string, error)
	Decrypt(value string) (string, error)
}

Encryptor 定义了数据加密接口

type ErrorCode added in v4.2.5

type ErrorCode string

ErrorCode represents error codes for security operations

const (
	ErrConfiguration ErrorCode = "CONFIGURATION_ERROR"
	ErrEncryption    ErrorCode = "ENCRYPTION_ERROR"
	ErrDecryption    ErrorCode = "DECRYPTION_ERROR"
)

type FieldSecurity

type FieldSecurity struct {
	MaskType     string
	NeedEncrypt  bool
	CustomFormat string
}

FieldSecurity 字段安全配置

type KeyRotationConfig added in v4.2.5

type KeyRotationConfig struct {
	Interval    time.Duration
	AutoRotate  bool
	BackupCount int
}

KeyRotationConfig defines the configuration for key rotation

type KeyRotationInfo added in v4.2.5

type KeyRotationInfo struct {
	LastRotation time.Time
	KeyVersion   int
	KeyID        string
}

KeyRotationInfo stores information about key rotation

type Masker

type Masker interface {
	Mask(value string, ruleType string) string
}

Masker 定义了数据脱敏接口

type SecurityManager

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

SecurityManager 安全管理器,集成脱敏和加密功能

func NewSecurityManager

func NewSecurityManager(key []byte) (*SecurityManager, error)

NewSecurityManager 创建安全管理器

func (*SecurityManager) DecryptData

func (sm *SecurityManager) DecryptData(value string) (string, error)

DecryptData 解密数据

func (*SecurityManager) EncryptData

func (sm *SecurityManager) EncryptData(value string) (string, error)

EncryptData 加密数据

func (*SecurityManager) MaskData

func (sm *SecurityManager) MaskData(value string, ruleType string) string

MaskData 脱敏数据

func (*SecurityManager) RotateKey added in v4.2.5

func (sm *SecurityManager) RotateKey() error

RotateKey performs key rotation based on the configured schedule

Jump to

Keyboard shortcuts

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