Created
February 13, 2020 17:00
-
-
Save mlampret/88e08251fb8bc63ab55e524fa49793f5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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