I'm using Jose library to create JWE's. I have successfully managed to create and parse JWE. JWT has fields like exp, iat which help in invalidating token after a certain period of time.
How can I set expiry on JWE ?
Here's what I've tried, without exp:
package main
import (
jose "gopkg.in/square/go-jose.v2"
)
// len(key) is 32
func CreateJWE(value, key string)(string, error){
encrypter, err := jose.NewEncrypter(jose.A256GCM, jose.Recipient{Algorithm: jose.A256GCMKW, Key: []byte(key)}, nil)
if err != nil {
return "", err
}
object, err := encrypter.Encrypt([]byte(value)])
if err != nil {
return "", err
}
return object.FullSerialize(), nil
}
func ParseJWE(jwe, key string)(string, error){
object, err := jose.ParseEncrypted(jwe)
if err != nil {
return "", err
}
b, err := (*object).Decrypt(key)
return string(b), err
}
jwt
subpackage. There is an example in the godoc: godoc.org/gopkg.in/square/go-jose.v2/jwt#example-Encrypted Thejwt.Claims
hasExpiry
, and it is that you are looking for. I hope it helps. – Burson