Wednesday, July 7, 2021

What is JWK

A JSON Web Key (JWK) is a JSON data structure that represents a set of public keys.

The JSON Web Key (JWK) data structure provides a convenient JSON representation for sets of public keys utilizing either the Elliptic Curve or RSA families of algorithms.

The following example JWK contains two public keys: one using an Elliptic Curve algorithm and a second one using an RSA algorithm. The first specifies that the key is to be used for encryption. Both provide a Key ID for matching purposes. In both cases, integers are represented using the base64url encoding of their big endian representations. (Long lines are broken are for display purposes only.)


{"jwk":

  [

    {"alg":"EC",

     "crv":"P-256",

     "x":"MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",

     "y":"4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",

     "use":"enc",

     "kid":"1"},


    {"alg":"RSA",

     "mod": "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx

4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMs

tn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2

QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbI

SD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqb

w0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw",

     "exp":"AQAB",

     "kid":"2011-04-29"}

  ]

}


A JWK consists of a JWK Container Object, which is a JSON object that contains an array of JWK Key Objects as a member. This section specifies the format of these objects.



JWK Container Object Format


A JWK Container Object is a JSON object containing a specific member. This member is:



Member Name JSON Value Type Container Object Member Semantics

jwk array The jwk member value contains an array of JWK Key Objects. This member is REQUIRED.



JWK Key Object Format


A JWK Key Object is a JSON object containing specific members. Those members that are common to all key types are as follows:


alg string The alg member identifies the cryptographic algorithm family used with the key. Values defined by this specification are EC and RSA. Specific additional members are required to represent the key, depending upon the alg value. The alg value is case sensitive. This member is REQUIRED.

use string The use member identifies the intended use of the key. Values defined by this specification are sig (signature) and enc (encryption). Other values MAY be used. The use value is case sensitive. This member is OPTIONAL.

kid string The kid (Key ID) member can be used to match a specific key. This can be used, for instance, to choose among a set of keys within the JWK during key rollover. The kid value MAY correspond to a JWS kid value. The interpretation of the kid value is unspecified. This member is OPTIONAL.




JWK Key Object Members for Elliptic Curve Keys


WKs can represent Elliptic Curve [FIPS.186‑3] keys. In this case, the alg member value MUST be EC. Furthermore, these additional members MUST be present:


crv string The crv member identifies the cryptographic curve used with the key. Values defined by this specification are P-256, P-384 and P-521. Additional crv values MAY be used, provided they are understood by implementations using that Elliptic Curve key. The crv value is case sensitive.

x string The x member contains the x coordinate for the elliptic curve point. It is represented as the base64url encoding of the coordinate's big endian representation.

y string The y member contains the y coordinate for the elliptic curve point. It is represented as the base64url encoding of the coordinate's big endian representation.



JWK Key Object Members for RSA Keys


JWKs can represent RSA [RFC3447] keys. In this case, the alg member value MUST be RSA. Furthermore, these additional members MUST be present:


Member Name JSON Value Type Key Object Member Semantics

mod string The mod member contains the modulus value for the RSA public key. It is represented as the base64url encoding of the value's big endian representation.

exp string The exp member contains the exponent value for the RSA public key. It is represented as the base64url encoding of the value's big endian representation.

Base64url encoding as used by JWKs

JWKs make use of the base64url encoding as defined in RFC 4648 [RFC4648]. As allowed by Section 3.2 of the RFC, this specification mandates that base64url encoding when used with JWKs MUST NOT use padding. Notes on implementing base64url encoding can be found in the JWS [JWS] specification.


references:

https://openid.net/specs/draft-jones-json-web-key-03.html#:~:text=A%20JSON%20Web%20Key%20(JWK,a%20set%20of%20public%20keys.


No comments:

Post a Comment