func GenerateECJWK(kid string, alg string, use string, prv_key ecdsa.PrivateKey) (*JWK, error) { x_base64 := cyhbase64.EncodeURLSafe(prv_key.X.Bytes()) y_base64 := cyhbase64.EncodeURLSafe(prv_key.Y.Bytes()) var base_jwk *JWK base_jwk.Kid = kid base_jwk.Kty = "EC" base_jwk.Crv = prv_key.Curve.Params().Name base_jwk.Alg = alg base_jwk.Use = use base_jwk.X = x_base64 base_jwk.Y = y_base64 return base_jwk, nil }
func GenerateRSAJWK(kid string, alg string, use string, prv_key *rsa.PrivateKey) (*JWK, error) { buf_exponent := new(bytes.Buffer) num_exponent := uint32(prv_key.PublicKey.E) err_exponent := binary.Write(buf_exponent, binary.BigEndian, num_exponent) if err_exponent != nil { return nil, err_exponent } trim_buf_exponent := bytes.TrimLeft(buf_exponent.Bytes(), "\x00") exponent_base64 := cyhbase64.EncodeURLSafe(trim_buf_exponent) modulus_base64 := cyhbase64.EncodeURLSafe(prv_key.PublicKey.N.Bytes()) var base_jwk *JWK base_jwk.Kid = kid base_jwk.Kty = "RSA" base_jwk.Alg = alg base_jwk.Use = use base_jwk.N = modulus_base64 base_jwk.E = exponent_base64 return base_jwk, nil }