Package edu.uiuc.ncsa.security.util.jwk
Class JSONWebKeyUtil
- java.lang.Object
- 
- edu.uiuc.ncsa.security.util.jwk.JSONWebKeyUtil
 
- 
 public class JSONWebKeyUtil extends Object 
- 
- 
Field SummaryFields Modifier and Type Field Description static StringALGORITHMstatic StringDEFAULT_KEY_ID_TAGstatic StringJSON_WEB_KEYS_TAGprotected static JWKUtil2jwkUtil2static StringMODULUSstatic StringPRIVATE_EXPONENTstatic StringPUBLIC_EXPONENTstatic StringRSA_COEFFICIENTSstatic StringRSA_EXPONENT_1static StringRSA_EXPONENT_2static StringRSA_PRIME_1static StringRSA_PRIME_2
 - 
Constructor SummaryConstructors Constructor Description JSONWebKeyUtil()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static JSONWebKeycreate(KeyPair keyPair)Create a newJSONWebKeyfrom a key pair.static JSONWebKeysfromJSON(File file)Read a set of keys from a file.static JSONWebKeysfromJSON(String raw)static JSONWebKeysfromJSON(net.sf.json.JSON json)Takes either a standard JSON object of keys: {"keys":[...]} or a single key and turns it in a set of web keysstatic JSONWebKeysfromXML(XMLEventReader xer)This is not a complete deserialization, but is part of a larger scheme.static JSONWebKeygetJsonWebKey(String rawJSON)Takes the serialized form of a single JSON web key and returns the object.static JWKUtil2getJwkUtil2()static JSONWebKeymakePublic(JSONWebKey key)static JSONWebKeysmakePublic(JSONWebKeys keys)Very useful utility to take a set of keys and return another set of keys that are only the public parts.static voidsetJwkUtil2(JWKUtil2 jwkUtil)static net.sf.json.JSONObjecttoJSON(JSONWebKey webKey)static net.sf.json.JSONObjecttoJSON(JSONWebKeys webKeys)Serialize a set of keys (as a java object) to JSON.static voidtoXML(JSONWebKeys jwks, XMLStreamWriter xsw)Not a complete serialization -- this is used to insert JSONweb keys into a larger serialization scheme.
 
- 
- 
- 
Field Detail- 
jwkUtil2protected static JWKUtil2 jwkUtil2 
 - 
ALGORITHMpublic static final String ALGORITHM - See Also:
- Constant Field Values
 
 - 
MODULUSpublic static final String MODULUS - See Also:
- Constant Field Values
 
 - 
PUBLIC_EXPONENTpublic static final String PUBLIC_EXPONENT - See Also:
- Constant Field Values
 
 - 
PRIVATE_EXPONENTpublic static final String PRIVATE_EXPONENT - See Also:
- Constant Field Values
 
 - 
RSA_PRIME_1public static final String RSA_PRIME_1 - See Also:
- Constant Field Values
 
 - 
RSA_PRIME_2public static final String RSA_PRIME_2 - See Also:
- Constant Field Values
 
 - 
RSA_EXPONENT_1public static final String RSA_EXPONENT_1 - See Also:
- Constant Field Values
 
 - 
RSA_EXPONENT_2public static final String RSA_EXPONENT_2 - See Also:
- Constant Field Values
 
 - 
RSA_COEFFICIENTSpublic static final String RSA_COEFFICIENTS - See Also:
- Constant Field Values
 
 - 
DEFAULT_KEY_ID_TAGpublic static final String DEFAULT_KEY_ID_TAG - See Also:
- Constant Field Values
 
 - 
JSON_WEB_KEYS_TAGpublic static final String JSON_WEB_KEYS_TAG - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getJwkUtil2public static JWKUtil2 getJwkUtil2() 
 - 
setJwkUtil2public static void setJwkUtil2(JWKUtil2 jwkUtil) 
 - 
fromJSONpublic static JSONWebKeys fromJSON(File file) throws IOException Read a set of keys from a file. The format of the file is that of the spec.- Parameters:
- file-
- Returns:
- Throws:
- NoSuchAlgorithmException
- InvalidKeySpecException
- IOException
 
 - 
fromJSONpublic static JSONWebKeys fromJSON(String raw) 
 - 
fromJSONpublic static JSONWebKeys fromJSON(net.sf.json.JSON json) throws NoSuchAlgorithmException, InvalidKeySpecException Takes either a standard JSON object of keys: {"keys":[...]} or a single key and turns it in a set of web keys- Parameters:
- json-
- Returns:
- Throws:
- NoSuchAlgorithmException
- InvalidKeySpecException
 
 - 
getJsonWebKeypublic static JSONWebKey getJsonWebKey(String rawJSON) Takes the serialized form of a single JSON web key and returns the object. This is a compliment totoJSON(JSONWebKey).- Parameters:
- rawJSON-
- Returns:
 
 - 
toJSONpublic static net.sf.json.JSONObject toJSON(JSONWebKeys webKeys) Serialize a set of keys (as a java object) to JSON.- Parameters:
- webKeys-
- Returns:
 
 - 
toJSONpublic static net.sf.json.JSONObject toJSON(JSONWebKey webKey) 
 - 
createpublic static JSONWebKey create(KeyPair keyPair) Create a newJSONWebKeyfrom a key pair. This creates a new random id too. This defaults to an algorithm of RS256. Remember that the algorithm is intended to show which algorithm consumers of this key expect, but has zero bearing on the key structure itself. If you want a different algorithm, such as RS384 or RS512, just change it.- Parameters:
- keyPair-
- Returns:
 
 - 
makePublicpublic static JSONWebKeys makePublic(JSONWebKeys keys) Very useful utility to take a set of keys and return another set of keys that are only the public parts. This set, for instance, can be returned as a response to public requests.- Parameters:
- keys-
- Returns:
 
 - 
makePublicpublic static JSONWebKey makePublic(JSONWebKey key) 
 - 
toXMLpublic static void toXML(JSONWebKeys jwks, XMLStreamWriter xsw) throws XMLStreamException Not a complete serialization -- this is used to insert JSONweb keys into a larger serialization scheme.- Parameters:
- jwks-
- xsw-
- Throws:
- XMLStreamException
 
 - 
fromXMLpublic static JSONWebKeys fromXML(XMLEventReader xer) throws XMLStreamException, InvalidKeySpecException, NoSuchAlgorithmException This is not a complete deserialization, but is part of a larger scheme. The assumption is that the cursor for the stream is positioned at the start tag for JSON web keys.
 
- 
 
-