Created
May 16, 2022 06:26
-
-
Save lestrrat/1d976bbdff13e8248588c7131fa75caa to your computer and use it in GitHub Desktop.
This file contains 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
// https://github.com/lestrrat-go/jwx/blob/129e8b1d3bc86038ded5b41e8720b120194074f8/examples/jwk_parse_key_example_test.go | |
package examples_test | |
import ( | |
"encoding/json" | |
"fmt" | |
"os" | |
"github.com/lestrrat-go/jwx/v2/jwk" | |
) | |
func ExampleJWK_ParseKey() { | |
const src = `{ | |
"kty":"EC", | |
"crv":"P-256", | |
"x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4", | |
"y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM", | |
"use":"enc", | |
"kid":"1" | |
}` | |
key, err := jwk.ParseKey([]byte(src)) | |
if err != nil { | |
fmt.Printf("failed parse key: %s\n", err) | |
return | |
} | |
json.NewEncoder(os.Stdout).Encode(key) | |
// OUTPUT: | |
// {"crv":"P-256","kid":"1","kty":"EC","use":"enc","x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4","y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM"} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment