com.nimbusds.jose.jwk
Class JWK

java.lang.Object
  extended by com.nimbusds.jose.jwk.JWK
All Implemented Interfaces:
net.minidev.json.JSONAware
Direct Known Subclasses:
ECKey, OctetSequenceKey, RSAKey

public abstract class JWK
extends Object
implements net.minidev.json.JSONAware

The base abstract class for JSON Web Keys (JWKs). It serialises to a JSON object.

The following JSON object members are common to all JWK types:

Example JWK (of the Elliptic Curve type):

 {
   "kty" : "EC",
   "crv" : "P-256",
   "x"   : "MKBCTNIcKUSDii11ySs3526iDZ8AiTo7Tu6KPAqv7D4",
   "y"   : "4Etl6SRW2YiLUrN5vfvVHuhp7x8PxltmWWlbbM4IFyM",
   "use" : "enc",
   "kid" : "1"
 }
 

Version:
$version$ (2013-03-19)
Author:
Vladimir Dzhuvinov, Justin Richer

Constructor Summary
JWK(KeyType kty, Use use, Algorithm alg, String kid)
          Creates a new JSON Web Key (JWK).
 
Method Summary
 Algorithm getAlgorithm()
          Gets the intended JOSE algorithm (alg) for this JWK.
 String getKeyID()
          Gets the ID (kid) of this JWK.
 KeyType getKeyType()
          Gets the type (kty) of this JWK.
 Use getKeyUse()
          Gets the use (use) of this JWK.
abstract  boolean isPrivate()
          Returns true if this JWK contains private or sensitive (non-public) parameters.
static JWK parse(net.minidev.json.JSONObject jsonObject)
          Parses a JWK from the specified JSON object representation.
static JWK parse(String s)
          Parses a JWK from the specified JSON object string representation.
protected static Algorithm parseAlgorithm(net.minidev.json.JSONObject jsonObject)
          Parses an algorithm (alg) parameter from the specified JSON object representation of a JWK.
protected static String parseKeyID(net.minidev.json.JSONObject jsonObject)
          Parses a key ID (kid) parameter from the specified JSON object representation of a JWK.
protected static Use parseKeyUse(net.minidev.json.JSONObject jsonObject)
          Parses a key use (use) parameter from the specified JSON object representation of a JWK.
 net.minidev.json.JSONObject toJSONObject()
          Returns a JSON object representation of this JWK.
 String toJSONString()
          Returns the JSON object string representation of this JWK.
abstract  JWK toPublicJWK()
          Creates a copy of this JWK with all private or sensitive parameters removed.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JWK

public JWK(KeyType kty,
           Use use,
           Algorithm alg,
           String kid)
Creates a new JSON Web Key (JWK).

Parameters:
kty - The key type. Must not be null.
use - The key use, null if not specified or if the key is intended for signing as well as encryption.
alg - The intended JOSE algorithm for the key, null if not specified.
kid - The key ID, null if not specified.
Method Detail

getKeyType

public KeyType getKeyType()
Gets the type (kty) of this JWK.

Returns:
The key type.

getKeyUse

public Use getKeyUse()
Gets the use (use) of this JWK.

Returns:
The key use, null if not specified or if the key is intended for signing as well as encryption.

getAlgorithm

public Algorithm getAlgorithm()
Gets the intended JOSE algorithm (alg) for this JWK.

Returns:
The intended JOSE algorithm, null if not specified.

getKeyID

public String getKeyID()
Gets the ID (kid) of this JWK. The key ID can be used to match a specific key. This can be used, for instance, to choose a key within a JWKSet during key rollover. The key ID may also correspond to a JWS/JWE kid header parameter value.

Returns:
The key ID, null if not specified.

isPrivate

public abstract boolean isPrivate()
Returns true if this JWK contains private or sensitive (non-public) parameters.

Returns:
true if this JWK contains private parameters, else false.

toPublicJWK

public abstract JWK toPublicJWK()
Creates a copy of this JWK with all private or sensitive parameters removed.

Returns:
The newly created public JWK, or null if none can be created.

toJSONObject

public net.minidev.json.JSONObject toJSONObject()
Returns a JSON object representation of this JWK. This method is intended to be called from extending classes.

Example:

 {
   "kty" : "RSA",
   "use" : "sig",
   "kid" : "fd28e025-8d24-48bc-a51a-e2ffc8bc274b"
 }
 

Returns:
The JSON object representation.

toJSONString

public String toJSONString()
Returns the JSON object string representation of this JWK.

Specified by:
toJSONString in interface net.minidev.json.JSONAware
Returns:
The JSON object string representation.

toString

public String toString()
Overrides:
toString in class Object
See Also:
toJSONString()

parse

public static JWK parse(String s)
                 throws ParseException
Parses a JWK from the specified JSON object string representation. The JWK must be an ECKey, an RSAKey, or a OctetSequenceKey.

Parameters:
s - The JSON object string to parse. Must not be null.
Returns:
The JWK.
Throws:
ParseException - If the string couldn't be parsed to a supported JWK.

parse

public static JWK parse(net.minidev.json.JSONObject jsonObject)
                 throws ParseException
Parses a JWK from the specified JSON object representation. The JWK must be an ECKey, an RSAKey, or a OctetSequenceKey.

Parameters:
jsonObject - The JSON object to parse. Must not be null.
Returns:
The JWK.
Throws:
ParseException - If the JSON object couldn't be parsed to a supported JWK.

parseKeyUse

protected static Use parseKeyUse(net.minidev.json.JSONObject jsonObject)
                          throws ParseException
Parses a key use (use) parameter from the specified JSON object representation of a JWK.

Parameters:
jsonObject - The JSON object to parse. Must not be null.
Returns:
The key use, null if not specified.
Throws:
ParseException - If the key use parameter couldn't be parsed.

parseAlgorithm

protected static Algorithm parseAlgorithm(net.minidev.json.JSONObject jsonObject)
                                   throws ParseException
Parses an algorithm (alg) parameter from the specified JSON object representation of a JWK.

Note that the algorithm requirement level is not inferred.

Parameters:
jsonObject - The JSON object to parse. Must not be null.
Returns:
The algorithm, null if not specified.
Throws:
ParseException - If the algorithm parameter couldn't be parsed.

parseKeyID

protected static String parseKeyID(net.minidev.json.JSONObject jsonObject)
                            throws ParseException
Parses a key ID (kid) parameter from the specified JSON object representation of a JWK.

Parameters:
jsonObject - The JSON object to parse. Must not be null.
Returns:
The key ID, null if not specified.
Throws:
ParseException - If the key ID parameter couldn't be parsed.


Copyright © 2013 NimbusDS. All Rights Reserved.