Documentation
¶
Overview ¶
Package security contains MooX's shared security primitives.
Index ¶
- Variables
- func CheckPrivateFile(path string) error
- func Decrypt(ciphertext, secret string) (string, error)
- func Encrypt(plaintext, secret string) (string, error)
- func HMACSHA256Hex(secret string, data []byte) string
- func HashPassword(password string) (string, error)
- func NewSalt() (string, error)
- func ParseToken(raw, secret string) (map[string]any, error)
- func RandomHex(size int) (string, error)
- func SHA256Hex(data []byte) string
- func SignToken(claims map[string]any, secret, issuer string, ttl time.Duration) (string, error)
- func VerifyPassword(password, encodedHash string) bool
Constants ¶
This section is empty.
Variables ¶
Functions ¶
func CheckPrivateFile ¶
CheckPrivateFile 检查保存凭据的私密文件:必须是普通文件、不是符号链接,并且只有当前用户能访问。 “只有当前用户能访问”按平台判断:Unix 上权限必须是 0600;Windows 的文件模式表示不了,改查 ACL (只允许当前用户、SYSTEM 与 Administrators,不能含 Everyone、Users、Authenticated Users 等)。
func Encrypt ¶
Encrypt encrypts plaintext with AES-256-GCM. The key is derived from secret with SHA-256, so callers do not need to coordinate AES key lengths. Secret must already contain high-entropy key material; this function is not a password-based key derivation function.
func HMACSHA256Hex ¶
HMACSHA256Hex returns the lowercase hexadecimal HMAC-SHA256 of data.
func HashPassword ¶
HashPassword hashes a password with bcrypt. The encoded result contains the randomly generated salt and cost, so callers do not store a second salt.
func ParseToken ¶
ParseToken verifies an HS256 token and returns its generic claims.
func SignToken ¶
SignToken signs generic claims with HS256. Business-specific claim validation belongs to the caller, not this package.
func VerifyPassword ¶
VerifyPassword reports whether password matches a bcrypt encoded hash.
Types ¶
This section is empty.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package domainpolicy matches explicit DNS names and subdomain suffixes.
|
Package domainpolicy matches explicit DNS names and subdomain suffixes. |