security

package
v0.8.1 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCipherConfig = CipherConfig{
	Cipher: "AES-128-CBC",
	AllowedCiphers: map[string][]int{
		"AES-128-CBC": {16, 16},
		"AES-192-CBC": {16, 24},
		"AES-256-CBC": {16, 32},
	},
	KdfHash:              "sha256",
	MacHash:              "sha256",
	AuthKeyInfo:          "AuthorizationKey",
	DerivationIterations: 100000,
}

DefaultCipherConfig is the default cipher configuration

Functions

func Decrypt

func Decrypt(data, secret string, passwordBased bool, config CipherConfig) (string, error)

Decrypt decrypts data using a password or a key

func Encrypt

func Encrypt(data, secret string, passwordBased bool, config CipherConfig) (string, error)

Encrypt encrypts data using a password or a key

func GenerateRandomBytes

func GenerateRandomBytes(length int) ([]byte, error)

GenerateRandomBytes generates random bytes of specified length

func PasswordHash

func PasswordHash(password string, cost int) (string, error)

PasswordHash generates a hash of the password

func PasswordVerify

func PasswordVerify(password, hash string) bool

PasswordVerify validates the password against a given hash

Types

type AES

type AES struct {
	Text string `json:"text" default:""`
	Key  string `json:"key" default:"jcbase.aes_key__"`
	Iv   string `json:"iv" default:"jcbase.aes_iv___"`
}

func (AES) Decrypt

func (a AES) Decrypt(plaintext *string) error

Decrypt decrypts the given cipherText using the provided key and iv

func (AES) Encrypt

func (a AES) Encrypt(cipherText *string) error

Encrypt encrypts the given text using the provided key and iv

type CipherConfig

type CipherConfig struct {
	Cipher               string
	AllowedCiphers       map[string][]int
	KdfHash              string
	MacHash              string
	AuthKeyInfo          string
	DerivationIterations int
}

CipherConfig stores the cipher configuration

type Input

type Input struct {
	Value        interface{}
	DefaultValue interface{}
}

func (Input) Belong

func (s Input) Belong(allow interface{}, strict bool) interface{}

Belong 检查值是否属于允许列表

func (Input) Html

func (s Input) Html() string

Html 清理并返回HTML内容

func (Input) Sanitize

func (s Input) Sanitize() interface{}

Sanitize 自动判断类型并进行通用清理

func (Input) SanitizeString added in v0.8.0

func (s Input) SanitizeString(str string, args ...any) string

SanitizeString 清理字符串以防止 SQL 注入和 XSS 攻击

Jump to

Keyboard shortcuts

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