Documentation
¶
Index ¶
- func GetDefaultHeaders() map[string]string
- func IsSecurePassword(password string) bool
- func MaskString(s string) string
- type APIKeyGenerator
- type CORSConfig
- type Crypto
- func (c *Crypto) Decrypt(encrypted []byte) ([]byte, error)
- func (c *Crypto) Encrypt(data []byte) ([]byte, error)
- func (c *Crypto) GenerateSignature(data string) string
- func (c *Crypto) HashPassword(password string) (string, error)
- func (c *Crypto) VerifyPassword(password, hash string) bool
- func (c *Crypto) VerifySignature(data, signature string) bool
- type CryptoTool
- func (c *CryptoTool) DecryptAES(ciphertext []byte) ([]byte, error)
- func (c *CryptoTool) DecryptString(encrypted string) (string, error)
- func (c *CryptoTool) EncryptAES(plaintext []byte) ([]byte, error)
- func (c *CryptoTool) EncryptString(plaintext string) (string, error)
- func (c *CryptoTool) GenerateRandomBytes(length int) ([]byte, error)
- func (c *CryptoTool) GenerateRandomString(length int) (string, error)
- func (c *CryptoTool) GenerateSignature(data string) string
- func (c *CryptoTool) HashPassword(password string) (string, error)
- func (c *CryptoTool) VerifyPassword(password, hash string) bool
- func (c *CryptoTool) VerifySignature(data, signature string) bool
- type EncryptionManager
- type HMACHash
- type HashAlgorithm
- type JWTManager
- type JWTToken
- type PasswordValidator
- type RateLimitConfig
- type RateLimiter
- type SHA256Hash
- type SecurityConfig
- type SecurityEvent
- type SecurityHeaders
- type SecurityMiddleware
- type SecurityMonitor
- type SecurityValidator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type APIKeyGenerator ¶
type APIKeyGenerator struct {
// contains filtered or unexported fields
}
APIKeyGenerator API Key 生成器
func NewAPIKeyGenerator ¶
func NewAPIKeyGenerator(prefix string) *APIKeyGenerator
NewAPIKeyGenerator 创建 API Key 生成器
func (*APIKeyGenerator) Generate ¶
func (g *APIKeyGenerator) Generate() (string, error)
Generate 生成 API Key
type CORSConfig ¶
type CORSConfig struct {
Enabled bool
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
AllowCredentials bool
MaxAge int
}
CORSConfig CORS 配置
type Crypto ¶
type Crypto struct {
// contains filtered or unexported fields
}
Crypto 加密工具
func (*Crypto) GenerateSignature ¶
GenerateSignature 生成签名
func (*Crypto) HashPassword ¶
HashPassword 哈希密码
func (*Crypto) VerifyPassword ¶
VerifyPassword 验证密码
func (*Crypto) VerifySignature ¶
VerifySignature 验证签名
type CryptoTool ¶
type CryptoTool struct {
// contains filtered or unexported fields
}
CryptoTool 加密工具
func (*CryptoTool) DecryptAES ¶
func (c *CryptoTool) DecryptAES(ciphertext []byte) ([]byte, error)
DecryptAES AES 解密
func (*CryptoTool) DecryptString ¶
func (c *CryptoTool) DecryptString(encrypted string) (string, error)
DecryptString 解密字符串
func (*CryptoTool) EncryptAES ¶
func (c *CryptoTool) EncryptAES(plaintext []byte) ([]byte, error)
EncryptAES AES 加密
func (*CryptoTool) EncryptString ¶
func (c *CryptoTool) EncryptString(plaintext string) (string, error)
EncryptString 加密字符串
func (*CryptoTool) GenerateRandomBytes ¶
func (c *CryptoTool) GenerateRandomBytes(length int) ([]byte, error)
GenerateRandomBytes 生成随机字节
func (*CryptoTool) GenerateRandomString ¶
func (c *CryptoTool) GenerateRandomString(length int) (string, error)
GenerateRandomString 生成随机字符串
func (*CryptoTool) GenerateSignature ¶
func (c *CryptoTool) GenerateSignature(data string) string
GenerateSignature 生成签名
func (*CryptoTool) HashPassword ¶
func (c *CryptoTool) HashPassword(password string) (string, error)
HashPassword 使用 Bcrypt 模拟(简化版)
func (*CryptoTool) VerifyPassword ¶
func (c *CryptoTool) VerifyPassword(password, hash string) bool
VerifyPassword 验证密码
func (*CryptoTool) VerifySignature ¶
func (c *CryptoTool) VerifySignature(data, signature string) bool
VerifySignature 验证签名
type EncryptionManager ¶
type EncryptionManager struct {
// contains filtered or unexported fields
}
EncryptionManager 加密管理器
func NewEncryptionManager ¶
func NewEncryptionManager(aesKey string) *EncryptionManager
NewEncryptionManager 创建加密管理器
func (*EncryptionManager) DecryptString ¶
func (e *EncryptionManager) DecryptString(ciphertext string) (string, error)
DecryptString 解密字符串
func (*EncryptionManager) EncryptString ¶
func (e *EncryptionManager) EncryptString(plaintext string) (string, error)
EncryptString 加密字符串
type HMACHash ¶
type HMACHash struct {
// contains filtered or unexported fields
}
HMACHash HMAC 哈希
func NewHMACHash ¶
type HashAlgorithm ¶
HashAlgorithm 哈希算法接口
type JWTManager ¶
type JWTManager struct {
// contains filtered or unexported fields
}
JWTManager JWT 管理器
type JWTToken ¶
type JWTToken struct {
Header map[string]interface{}
Payload map[string]interface{}
Signature string
}
JWTToken JWT Token 结构
type PasswordValidator ¶
type PasswordValidator struct {
// contains filtered or unexported fields
}
PasswordValidator 密码验证器
func NewPasswordValidator ¶
func NewPasswordValidator() *PasswordValidator
NewPasswordValidator 创建密码验证器
type RateLimitConfig ¶
type RateLimitConfig struct {
RequestsPerMinute int
RequestsPerHour int
RequestsPerDay int
Burst int
}
RateLimitConfig 限流配置
type RateLimiter ¶
type RateLimiter struct {
// contains filtered or unexported fields
}
RateLimiter 限流器
type SHA256Hash ¶
type SHA256Hash struct{}
SHA256Hash SHA256 哈希
func (*SHA256Hash) Hash ¶
func (h *SHA256Hash) Hash(data []byte) []byte
type SecurityConfig ¶
type SecurityConfig struct {
CORS CORSConfig
Helmet bool
IPWhitelist []string
IPBlacklist []string
RequestSize int64
EnableCSRF bool
EnableRateLimit bool
}
SecurityConfig 安全配置
type SecurityEvent ¶
SecurityEvent 安全事件
type SecurityHeaders ¶
type SecurityHeaders struct {
// contains filtered or unexported fields
}
SecurityHeaders 安全头管理器
func (*SecurityHeaders) Apply ¶
func (s *SecurityHeaders) Apply(w http.ResponseWriter)
Apply 应用到 ResponseWriter
type SecurityMiddleware ¶
type SecurityMiddleware struct {
// contains filtered or unexported fields
}
SecurityMiddleware 安全中间件
func NewSecurityMiddleware ¶
func NewSecurityMiddleware(config SecurityConfig) *SecurityMiddleware
NewSecurityMiddleware 创建安全中间件
type SecurityMonitor ¶
type SecurityMonitor struct {
// contains filtered or unexported fields
}
SecurityMonitor 安全监控
func (*SecurityMonitor) GetEvents ¶
func (m *SecurityMonitor) GetEvents() []SecurityEvent
GetEvents 获取安全事件
func (*SecurityMonitor) GetEventsByType ¶
func (m *SecurityMonitor) GetEventsByType(eventType string) []SecurityEvent
GetEventsByType 按类型获取事件
func (*SecurityMonitor) RecordEvent ¶
func (m *SecurityMonitor) RecordEvent(event SecurityEvent)
RecordEvent 记录安全事件
type SecurityValidator ¶
type SecurityValidator struct {
// contains filtered or unexported fields
}
SecurityValidator 安全验证器
func NewSecurityValidator ¶
func NewSecurityValidator(secretKey string) *SecurityValidator
NewSecurityValidator 创建安全验证器
func (*SecurityValidator) SanitizeInput ¶
func (v *SecurityValidator) SanitizeInput(input string) string
SanitizeInput 清理输入
func (*SecurityValidator) ValidateInput ¶
func (v *SecurityValidator) ValidateInput(input string) error
ValidateInput 验证输入