jwtutil

package
v1.4.4 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrECDSANilPubKey is the error for trying to verify a JWT with a nil public key.
	ErrECDSANilPubKey = errors.New("jwt: ECDSA public key is nil")
	// ErrECDSAVerification is the error for an invalid ECDSA signature.
	ErrECDSAVerification = errors.New("jwt: ECDSA verification failed")

	// ErrRSANilPubKey is the error for trying to verify a JWT with a nil public key.
	ErrRSANilPubKey = errors.New("jwt: RSA public key is nil")
	// ErrRSAVerification is the error for an invalid RSA signature.
	ErrRSAVerification = errors.New("jwt: RSA verification failed")

	// ErrHmacVerification is the error for an invalid RSA signature.
	ErrHmacVerification = errors.New("jwt: Hmac verification failed")
)

Functions

func ParseRsaPublicKeyByJWK

func ParseRsaPublicKeyByJWK(jsonBytes []byte) (publicKey *rsa.PublicKey, err error)

func RsaPublicKeyToJWK

func RsaPublicKeyToJWK(pub *rsa.PublicKey) ([]byte, error)

func VerifyJwtSign

func VerifyJwtSign(ciphertext, key []byte) (json.RawMessage, error)

VerifyJwtSign verify jwt sign text , key is hmac key or rsa/ecdsa public key

func VerifyJwtSignByEcdsa

func VerifyJwtSignByEcdsa(ciphertext []byte, publicKey *ecdsa.PublicKey) (json.RawMessage, error)

func VerifyJwtSignByHmacHash

func VerifyJwtSignByHmacHash(ciphertext, key []byte) (json.RawMessage, error)

func VerifyJwtSignByRsa

func VerifyJwtSignByRsa(ciphertext []byte, publicKey *rsa.PublicKey) (json.RawMessage, error)

Types

type JWK

type JWK struct {
	KTY       string `json:"kty"`
	KID       string `json:"kid"`
	Use       string `json:"use"`
	Algorithm string `json:"alg"`
	N         string `json:"n"`
	E         string `json:"e"`
}

type JwtPayload

type JwtPayload struct {
	JTI       string        `json:"jti"`
	IAT       int           `json:"iat"`
	EXP       int           `json:"exp"`
	NBF       int           `json:"nbf"`
	ISS       string        `json:"iss"`
	Sub       string        `json:"sub"`
	Aud       string        `json:"aud"`
	Roles     []interface{} `json:"roles"`
	AuthType  string        `json:"authType"`
	UserId    string        `json:"userId"`
	SubjectId string        `json:"subjectId"`
	Email     string        `json:"email"`
}

Jump to

Keyboard shortcuts

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