Skip to content

Instantly share code, notes, and snippets.

@mlampret
Created February 13, 2020 17:00
Show Gist options
  • Save mlampret/88e08251fb8bc63ab55e524fa49793f5 to your computer and use it in GitHub Desktop.
Save mlampret/88e08251fb8bc63ab55e524fa49793f5 to your computer and use it in GitHub Desktop.
// golang jwt jwe
func jwt2jwe(jwtStr string) string {
rec := jose.Recipient{
Algorithm: jose.PBES2_HS256_A128KW,
Key: "mypassphrase",
PBES2Count: 4096,
PBES2Salt: []byte("salt"),
}
enc, _ := jose.NewEncrypter(jose.A128CBC_HS256, rec, nil)
jweObj, _ := enc.Encrypt([]byte(jwtStr))
jweStr, _ := jweObj.CompactSerialize()
return jweStr
}
func jwe2jwt(jweStr string) string {
jweObj, _ := jose.ParseEncrypted(jweStr)
jwtBytes, _ := jweObj.Decrypt("mypassphrase")
jwtStr := string(jwtBytes)
return jwtStr
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment