Skip to content

A golang implementation of JSON Web Signature encoding and decoding.

License

Notifications You must be signed in to change notification settings

mushroomsir/jwsgo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

jsonrpc

Build Status Coverage Status License GoDoc

Installation

go get github.com/mushroomsir/jwsgo

Feature

  • HMAC signatures with HS256, HS384 and HS512.
  • Support custom algorithm for encrypt data.
  • Support custom Header
  • Easy to understand and use.

API

Basic usage

NewSha256 create the jws instance with HMAC-SHA256.

// or NewSha512, NewSha384
jws:=jwsgo.NewSha256("Secret-key")

// create the payload
payload := &Payload{
    Iss: "http://google.com/",
    Exp: 3610,
    Iat: 10,
}

// You can also add some extra fileds
payload.Set("userid", "123456")

// encode this payload and get token
token,err := jws.Encode(payload)

// decode token
playload,err := jws.Decode(token)

Custom Header

you can even make own Header with custom value.

header := &Header{
    Algorithm: "HS1",
}
header.Set("id", "mushroom")
token, err := jws.EncodeWith(header, payload)

Custom algorithm

use custom hash func for encrypt data.

hasher := func(data string) []byte {
    h := hmac.New(sha1.New, []byte("xx"))
    h.Write([]byte(data))
    return h.Sum(nil)
}
jws := New("HS256",hasher)

About

A golang implementation of JSON Web Signature encoding and decoding.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages