Skip to content

Instantly share code, notes, and snippets.

@lestrrat
Created May 16, 2022 06:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lestrrat/1d976bbdff13e8248588c7131fa75caa to your computer and use it in GitHub Desktop.
Save lestrrat/1d976bbdff13e8248588c7131fa75caa to your computer and use it in GitHub Desktop.
// 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