Documentation ¶
Index ¶
- Constants
- Variables
- func DecryptData(ep *Encipherer, typ DecryptType, src string, res any) error
- func EncryptData(ep *Encipherer, typ EncryptType, src any) (string, error)
- func EncryptDataRaw(ep *Encipherer, typ EncryptType, data []byte) (string, error)
- func JwtEncode(typ int, userId int64, expire time.Duration, secret string) (string, time.Time, error)
- type DecryptType
- type Encipherer
- func (e *Encipherer) AesCbcDecrypt(data string) ([]byte, error)
- func (e *Encipherer) AesCbcEncrypt(data []byte) (string, error)
- func (e *Encipherer) GetAesSecretKey() (string, string)
- func (e *Encipherer) RsaPrikeyDecrypt(data string) ([]byte, error)
- func (e *Encipherer) RsaPrikeyEncrypt(data []byte) (string, error)
- func (e *Encipherer) RsaPubkeyDecrypt(data string) ([]byte, error)
- func (e *Encipherer) RsaPubkeyEncrypt(data []byte) (string, error)
- type EncryptType
- type IdGenerator
- type IdOption
- type IdSourcer
- type IdStorer
- type JwtClaims
- type JwtData
- type JwtMiddleware
- type JwtUser
- type Option
Constants ¶
View Source
const ( TokenTypeNormal = 0 //普通token TokenTypeRefresh = 1 //刷新token )
Variables ¶
View Source
var (
ErrInvalidToken = errors.New("invalid token")
)
Functions ¶
func DecryptData ¶ added in v2.3.0
func DecryptData(ep *Encipherer, typ DecryptType, src string, res any) error
func EncryptData ¶ added in v2.3.0
func EncryptData(ep *Encipherer, typ EncryptType, src any) (string, error)
func EncryptDataRaw ¶ added in v2.10.18
func EncryptDataRaw(ep *Encipherer, typ EncryptType, data []byte) (string, error)
Types ¶
type DecryptType ¶ added in v2.3.0
type DecryptType int
const ( DecryptTypeAes DecryptType //1-aes解密 DecryptTypeRsaPrikey //2-rsa私钥解密 DecryptTypeRsaPubkey //2-rsa公钥解密 DecryptTypeNone //2-none )
type Encipherer ¶
type Encipherer struct {
// contains filtered or unexported fields
}
func NewEncipherer ¶
func NewEncipherer(options ...Option) *Encipherer
func (*Encipherer) AesCbcDecrypt ¶
func (e *Encipherer) AesCbcDecrypt(data string) ([]byte, error)
func (*Encipherer) AesCbcEncrypt ¶
func (e *Encipherer) AesCbcEncrypt(data []byte) (string, error)
func (*Encipherer) GetAesSecretKey ¶
func (e *Encipherer) GetAesSecretKey() (string, string)
func (*Encipherer) RsaPrikeyDecrypt ¶
func (e *Encipherer) RsaPrikeyDecrypt(data string) ([]byte, error)
func (*Encipherer) RsaPrikeyEncrypt ¶
func (e *Encipherer) RsaPrikeyEncrypt(data []byte) (string, error)
func (*Encipherer) RsaPubkeyDecrypt ¶
func (e *Encipherer) RsaPubkeyDecrypt(data string) ([]byte, error)
func (*Encipherer) RsaPubkeyEncrypt ¶
func (e *Encipherer) RsaPubkeyEncrypt(data []byte) (string, error)
type EncryptType ¶ added in v2.3.0
type EncryptType int
const ( EncryptTypeAes EncryptType //1-aes加密 EncryptTypeRsaPrikey //2-rsa私钥加密 EncryptTypeRsaPubkey //2-rsag公钥加密 EncryptTypeNone //-none )
type IdGenerator ¶ added in v2.8.0
type IdGenerator struct {
// contains filtered or unexported fields
}
func NewIdGenerator ¶ added in v2.8.0
func (*IdGenerator) NextId ¶ added in v2.8.0
func (g *IdGenerator) NextId() (int64, error)
func (*IdGenerator) Store ¶ added in v2.8.0
func (g *IdGenerator) Store() error
type IdOption ¶ added in v2.8.1
type IdOption func(ig *IdGenerator)
func WithIdStoreTime ¶ added in v2.8.1
type JwtClaims ¶ added in v2.9.0
type JwtClaims struct { Type int `json:"type"` //类型 0-普通tokn 1-刷新token UserId int64 `json:"user_id"` //用户ID Start int64 `json:"start"` //开始时间 Expire int64 `json:"expire"` //过期时间 }
func NewJwtClaims ¶ added in v2.9.0
func (*JwtClaims) TypeRefresh ¶ added in v2.9.0
type JwtMiddleware ¶
type JwtMiddleware struct {
// contains filtered or unexported fields
}
func NewJwtMiddleware ¶
func NewJwtMiddleware(user JwtUser) *JwtMiddleware
func (*JwtMiddleware) GetAuthor ¶
func (g *JwtMiddleware) GetAuthor() *jwt.GinJWTMiddleware
func (*JwtMiddleware) IdentityHandler ¶
func (g *JwtMiddleware) IdentityHandler(c *gin.Context) interface{}
func (*JwtMiddleware) PayloadFunc ¶
func (g *JwtMiddleware) PayloadFunc(data interface{}) jwt.MapClaims
type JwtUser ¶
type JwtUser interface { Authenticator(c *gin.Context) (interface{}, error) Unauthorized(c *gin.Context, code int, message string) // User can define own LoginResponse func. LoginResponse(c *gin.Context, code int, message string, time time.Time) // User can define own LogoutResponse func. LogoutResponse(c *gin.Context, code int) // User can define own RefreshResponse func. RefreshResponse(c *gin.Context, code int, message string, time time.Time) }
type Option ¶
type Option func(e *Encipherer)
func WithAesKey ¶
func WithRsaPriKey ¶
func WithRsaPubKey ¶
func WithSerializer ¶ added in v2.6.8
func WithSerializer(serializer serialize.Serializer) Option
func WithUnencrypt ¶ added in v2.9.2
Click to show internal directories.
Click to hide internal directories.