@Immutable public class JWKSet extends Object implements Serializable
JSON Web Keys
(JWKs) as the value of its "keys" member.
Additional (custom) members of the JWK Set JSON object are also supported.
Example JSON Web Key (JWK) set:
{ "keys" : [ { "kty" : "EC", "crv" : "P-256", "x" : "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4", "y" : "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM", "use" : "enc", "kid" : "1" }, { "kty" : "RSA", "n" : "0vx7agoebGcQSuuPiLJXZptN9nndrQmbXEps2aiAFbWhM78LhWx 4cbbfAAtVT86zwu1RK7aPFFxuhDR1L6tSoc_BJECPebWKRXjBZCiFV4n3oknjhMs tn64tZ_2W-5JsGY4Hc5n9yBXArwl93lqt7_RN5w6Cf0h4QyQ5v-65YGjQR0_FDW2 QvzqY368QQMicAtaSqzs8KJZgnYb9c7d0zgdAZHzu6qMQvRL5hajrn1n91CbOpbI SD08qNLyrdkt-bFTWhAI4vMQFh6WeZu0fM4lFd2NcRwr3XPksINHaQ-G_xBniIqb w0Ls1jF44-csFCur-kEgU8awapJzKnqDKgw", "e" : "AQAB", "alg" : "RS256", "kid" : "2011-04-29" } ] }
Modifier and Type | Field and Description |
---|---|
static String |
MIME_TYPE
The MIME type of JWK set objects:
application/jwk-set+json; charset=UTF-8 |
Constructor and Description |
---|
JWKSet()
Creates a new empty JSON Web Key (JWK) set.
|
JWKSet(JWK key)
Creates a new JSON Web Key (JWK) set with a single key.
|
JWKSet(List<JWK> keys)
Creates a new JSON Web Key (JWK) set with the specified keys.
|
JWKSet(List<JWK> keys,
Map<String,Object> customMembers)
Creates a new JSON Web Key (JWK) set with the specified keys and
additional custom members.
|
Modifier and Type | Method and Description |
---|---|
boolean |
containsJWK(JWK jwk)
Returns
true if this JWK set contains the specified JWK as
public or private key, by comparing its thumbprint with those of the
keys in the set. |
Map<String,Object> |
getAdditionalMembers()
Gets the additional custom members of this JSON Web Key (JWK) set.
|
JWK |
getKeyByKeyId(String kid)
Gets the key from this JSON Web Key (JWK) set as identified by its
Key ID (kid) member.
|
List<JWK> |
getKeys()
Gets the keys (ordered) of this JSON Web Key (JWK) set.
|
static JWKSet |
load(File file)
Loads a JSON Web Key (JWK) set from the specified file.
|
static JWKSet |
load(InputStream inputStream)
Loads a JSON Web Key (JWK) set from the specified input stream.
|
static JWKSet |
load(KeyStore keyStore,
PasswordLookup pwLookup)
Loads a JSON Web Key (JWK) set from the specified JCA key store.
|
static JWKSet |
load(URL url)
Loads a JSON Web Key (JWK) set from the specified URL.
|
static JWKSet |
load(URL url,
int connectTimeout,
int readTimeout,
int sizeLimit)
Loads a JSON Web Key (JWK) set from the specified URL.
|
static JWKSet |
load(URL url,
int connectTimeout,
int readTimeout,
int sizeLimit,
Proxy proxy)
Loads a JSON Web Key (JWK) set from the specified URL.
|
static JWKSet |
parse(Map<String,Object> json)
Parses the specified JSON object representing a JSON Web Key (JWK)
set.
|
static JWKSet |
parse(String s)
Parses the specified string representing a JSON Web Key (JWK) set.
|
Map<String,Object> |
toJSONObject()
Returns the JSON object representation of this JSON Web Key (JWK)
set.
|
Map<String,Object> |
toJSONObject(boolean publicKeysOnly)
Returns the JSON object representation of this JSON Web Key (JWK)
set.
|
JWKSet |
toPublicJWKSet()
Returns a copy of this JSON Web Key (JWK) set with all private keys
and parameters removed.
|
String |
toString()
Returns the JSON object string representation of this JSON Web Key
(JWK) set.
|
String |
toString(boolean publicKeysOnly)
Returns the JSON object string representation of this JSON Web Key
(JWK) set.
|
public static final String MIME_TYPE
application/jwk-set+json; charset=UTF-8
public JWKSet()
public JWKSet(JWK key)
key
- The JWK. Must not be null
.public JWKSet(List<JWK> keys)
keys
- The JWK list. Must not be null
.public List<JWK> getKeys()
public JWK getKeyByKeyId(String kid)
If more than one key exists in the JWK Set with the same identifier, this function returns only the first one in the set.
kid
- They key identifier.kid
or null
if no key
exists.public boolean containsJWK(JWK jwk) throws JOSEException
true
if this JWK set contains the specified JWK as
public or private key, by comparing its thumbprint with those of the
keys in the set.jwk
- The JWK to check. Must not be null
.true
if contained, false
if not.JOSEException
- If thumbprint computation failed.public Map<String,Object> getAdditionalMembers()
public JWKSet toPublicJWKSet()
public Map<String,Object> toJSONObject()
toJSONObject(boolean)
method if you
wish to include them.public Map<String,Object> toJSONObject(boolean publicKeysOnly)
publicKeysOnly
- Controls the inclusion of private keys and
parameters into the output JWK members. If
true
private keys and parameters will
be omitted. If false
all available key
parameters will be included.public String toString(boolean publicKeysOnly)
publicKeysOnly
- Controls the inclusion of private keys and
parameters into the output JWK members. If
true
private keys and parameters will
be omitted. If false
all available key
parameters will be included.public String toString()
public static JWKSet parse(String s) throws ParseException
s
- The string to parse. Must not be null
.ParseException
- If the string couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet parse(Map<String,Object> json) throws ParseException
json
- The JSON object to parse. Must not be null
.ParseException
- If the string couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(InputStream inputStream) throws IOException, ParseException
inputStream
- The JWK set input stream. Must not be null
.IOException
- If the input stream couldn't be read.ParseException
- If the input stream couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(File file) throws IOException, ParseException
file
- The JWK set file. Must not be null
.IOException
- If the file couldn't be read.ParseException
- If the file couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(URL url, int connectTimeout, int readTimeout, int sizeLimit) throws IOException, ParseException
url
- The JWK set URL. Must not be null
.connectTimeout
- The URL connection timeout, in milliseconds.
If zero no (infinite) timeout.readTimeout
- The URL read timeout, in milliseconds. If zero
no (infinite) timeout.sizeLimit
- The read size limit, in bytes. If zero no
limit.IOException
- If the file couldn't be read.ParseException
- If the file couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(URL url, int connectTimeout, int readTimeout, int sizeLimit, Proxy proxy) throws IOException, ParseException
url
- The JWK set URL. Must not be null
.connectTimeout
- The URL connection timeout, in milliseconds.
If zero no (infinite) timeout.readTimeout
- The URL read timeout, in milliseconds. If zero
no (infinite) timeout.sizeLimit
- The read size limit, in bytes. If zero no
limit.proxy
- The optional proxy to use when opening the
connection to retrieve the resource. If
null
, no proxy is used.IOException
- If the file couldn't be read.ParseException
- If the file couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(URL url) throws IOException, ParseException
url
- The JWK set URL. Must not be null
.IOException
- If the file couldn't be read.ParseException
- If the file couldn't be parsed to a valid
JSON Web Key (JWK) set.public static JWKSet load(KeyStore keyStore, PasswordLookup pwLookup) throws KeyStoreException
Important: The X.509 certificates are not validated!
keyStore
- The key store. Must not be null
.pwLookup
- The password lookup for password-protected keys,
null
if not specified.KeyStoreException
- On a key store exception.Copyright © 2021 Connect2id Ltd.. All rights reserved.