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 Summary
Fields Modifier and Type Field Description static String
ALGORITHM
static String
DEFAULT_KEY_ID_TAG
static String
JSON_WEB_KEYS_TAG
protected static JWKUtil2
jwkUtil2
static String
MODULUS
static String
PRIVATE_EXPONENT
static String
PUBLIC_EXPONENT
static String
RSA_COEFFICIENTS
static String
RSA_EXPONENT_1
static String
RSA_EXPONENT_2
static String
RSA_PRIME_1
static String
RSA_PRIME_2
-
Constructor Summary
Constructors Constructor Description JSONWebKeyUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static JSONWebKey
create(KeyPair keyPair)
Create a newJSONWebKey
from a key pair.static JSONWebKeys
fromJSON(File file)
Read a set of keys from a file.static JSONWebKeys
fromJSON(String raw)
static JSONWebKeys
fromJSON(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 JSONWebKeys
fromXML(XMLEventReader xer)
This is not a complete deserialization, but is part of a larger scheme.static JSONWebKey
getJsonWebKey(String rawJSON)
Takes the serialized form of a single JSON web key and returns the object.static JWKUtil2
getJwkUtil2()
static JSONWebKey
makePublic(JSONWebKey key)
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.static void
setJwkUtil2(JWKUtil2 jwkUtil)
static net.sf.json.JSONObject
toJSON(JSONWebKey webKey)
static net.sf.json.JSONObject
toJSON(JSONWebKeys webKeys)
Serialize a set of keys (as a java object) to JSON.static void
toXML(JSONWebKeys jwks, XMLStreamWriter xsw)
Not a complete serialization -- this is used to insert JSONweb keys into a larger serialization scheme.
-
-
-
Field Detail
-
jwkUtil2
protected static JWKUtil2 jwkUtil2
-
ALGORITHM
public static final String ALGORITHM
- See Also:
- Constant Field Values
-
MODULUS
public static final String MODULUS
- See Also:
- Constant Field Values
-
PUBLIC_EXPONENT
public static final String PUBLIC_EXPONENT
- See Also:
- Constant Field Values
-
PRIVATE_EXPONENT
public static final String PRIVATE_EXPONENT
- See Also:
- Constant Field Values
-
RSA_PRIME_1
public static final String RSA_PRIME_1
- See Also:
- Constant Field Values
-
RSA_PRIME_2
public static final String RSA_PRIME_2
- See Also:
- Constant Field Values
-
RSA_EXPONENT_1
public static final String RSA_EXPONENT_1
- See Also:
- Constant Field Values
-
RSA_EXPONENT_2
public static final String RSA_EXPONENT_2
- See Also:
- Constant Field Values
-
RSA_COEFFICIENTS
public static final String RSA_COEFFICIENTS
- See Also:
- Constant Field Values
-
DEFAULT_KEY_ID_TAG
public static final String DEFAULT_KEY_ID_TAG
- See Also:
- Constant Field Values
-
JSON_WEB_KEYS_TAG
public static final String JSON_WEB_KEYS_TAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getJwkUtil2
public static JWKUtil2 getJwkUtil2()
-
setJwkUtil2
public static void setJwkUtil2(JWKUtil2 jwkUtil)
-
fromJSON
public 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
-
fromJSON
public static JSONWebKeys fromJSON(String raw)
-
fromJSON
public 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
-
getJsonWebKey
public 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:
-
toJSON
public static net.sf.json.JSONObject toJSON(JSONWebKeys webKeys)
Serialize a set of keys (as a java object) to JSON.- Parameters:
webKeys
-- Returns:
-
toJSON
public static net.sf.json.JSONObject toJSON(JSONWebKey webKey)
-
create
public static JSONWebKey create(KeyPair keyPair)
Create a newJSONWebKey
from 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:
-
makePublic
public 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:
-
makePublic
public static JSONWebKey makePublic(JSONWebKey key)
-
toXML
public 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
-
fromXML
public 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.
-
-