miniutils

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2022 License: MIT Imports: 15 Imported by: 17

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrTokenFormat  = errors.New("token is not a JWT")
	ErrTokenExpired = errors.New("token is expired")
	ErrTokenSign    = errors.New("token sign error")
)

Functions

func Base64UrlDecode

func Base64UrlDecode(seg string) ([]byte, error)

Base64UrlDecode Decode JWT specific base64url encoding with padding stripped

func Base64UrlEncode

func Base64UrlEncode(seg []byte) string

Base64UrlEncode Encode JWT specific base64url encoding with padding stripped

func GetFileSha256

func GetFileSha256(path string) (hash string, err error)

GetFileSha256 get SHA256 hash of file.

func GetJwtBySecret

func GetJwtBySecret(keyBytes []byte, bodyInfo map[string]interface{}) (string, error)

func GetRandString

func GetRandString(l int) string

func GetSha256

func GetSha256(s string) string

GetSha256 get SHA256 hash. The len of SHA256 value is 64.

func GetSha256BySecret

func GetSha256BySecret(secret string, keyBytes []byte) []byte

GetSha256BySecret get SHA256 hash by Key

func JsonDecodeUseNumber

func JsonDecodeUseNumber(infoBytes []byte, result interface{}) error

func Md5

func Md5(s string) string

Md5 get the MD5 hash.

Types

type JsonWebToken

type JsonWebToken struct {
	TokenString string
	// contains filtered or unexported fields
}

func NewJwt

func NewJwt(secret string) *JsonWebToken

NewJwt init JsonWebToken by secret string

func (*JsonWebToken) Create

func (j *JsonWebToken) Create(claims map[string]interface{}, expiresin time.Duration) (token string, err error)

Create JsonWebToken string Create(map[string]interface{}{"id": 123456789, "username": "Harvey"}, time.Second*time.Duration(3600))

func (*JsonWebToken) Decode

func (j *JsonWebToken) Decode(jwtStr string) (segInfo map[string]interface{}, err error)

Decode reads the JsonWebToken string. Return the JWT decoded data.

func (*JsonWebToken) Parse

func (j *JsonWebToken) Parse(tokenStr string) (result map[string]interface{}, err error)

Decode reads the JsonWebToken string. Check the JWT decoded data and return.

Jump to

Keyboard shortcuts

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