Package edu.uiuc.ncsa.security.util.jwk
Class JWKUtil2
- java.lang.Object
-
- edu.uiuc.ncsa.security.util.jwk.JWKUtil2
-
- All Implemented Interfaces:
Serializable
public class JWKUtil2 extends Object implements Serializable
This is a utility that does all of the work for JSON webkeys. This is part of a conversion internally to JOSE.Created by Jeff Gaynor
on 10/26/23 at 8:41 AM- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String[]
ALL_EC_ALGORITHMS
static String[]
ALL_EC_CURVES
static String[]
ALL_RSA_ALGORITHMS
static String
EC_CURVE_ED_25519
static String
EC_CURVE_ED_448
static String
EC_CURVE_KEY
static String
EC_CURVE_P_256
static String
EC_CURVE_P_256K
static String
EC_CURVE_P_384
static String
EC_CURVE_P_521
static String
EC_CURVE_SEC_256K1
static String
EC_CURVE_X_25519
static String
EC_CURVE_X_448
static String
ES_256
Elliptic curve ES 256 key algorithmstatic String
ES_256K
Elliptic curve ES 256K key algorithmstatic String
ES_384
Elliptic curve ES 384 key algorithmstatic String
ES_512
Elliptic curve ES 512 key algorithmstatic String
EXPIRES_AT
static String
ISSUED_AT
static String
KEY_ID
static String
KEY_TYPE
static String
KEYS
static String
NOT_VALID_BEFORE
static String
RS_256
RSA 256 key algorithmstatic String
RS_384
RSA 384 key algorithmstatic String
RS_512
RSA 512 key algorithmstatic String
USE
-
Constructor Summary
Constructors Constructor Description JWKUtil2()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
bigIntToString(BigInteger bigInteger)
JSONWebKey
createECKey()
Create a webkey using the given named curve.JSONWebKey
createECKey(String curveName, String alg)
protected String
createID()
Create id with standard 8 byte lengthprotected String
createID(int count)
JSONWebKey
createRSAKey()
Create and RSA key with the default bit size (2048) and RS256 algorithm.JSONWebKey
createRSAKey(int length, String alg)
JSONWebKeys
fromJSON(File file)
JSONWebKeys
fromJSON(String x)
JSONWebKeys
fromJSON(net.sf.json.JSON json)
int
getIdLength()
JSONWebKey
getJsonWebKey(String rawJSON)
JSONWebKey
getJsonWebKey(net.sf.json.JSONObject json)
protected static net.sf.json.JSONObject
initToJSON(JSONWebKey webKey)
This creats a JSON object from theJSONWebKey
that serializes it in a spec compliant way, hence can be turned back into a JOSEJWK
.JSONWebKey
makePublic(JSONWebKey key)
JSONWebKeys
makePublic(JSONWebKeys keys)
void
setIdLength(int idLength)
net.sf.json.JSONObject
toJSON(JSONWebKey webKey)
net.sf.json.JSONObject
toJSON(JSONWebKeys webKeys)
protected net.sf.json.JSONObject
toJSONEC(JSONWebKey webKey)
protected net.sf.json.JSONObject
toJSONRSA(JSONWebKey webKey)
-
-
-
Field Detail
-
KEYS
public static final String KEYS
- See Also:
- Constant Field Values
-
KEY_ID
public static final String KEY_ID
- See Also:
- Constant Field Values
-
USE
public static final String USE
- See Also:
- Constant Field Values
-
KEY_TYPE
public static final String KEY_TYPE
- See Also:
- Constant Field Values
-
EC_CURVE_KEY
public static final String EC_CURVE_KEY
- See Also:
- Constant Field Values
-
ISSUED_AT
public static final String ISSUED_AT
- See Also:
- Constant Field Values
-
NOT_VALID_BEFORE
public static final String NOT_VALID_BEFORE
- See Also:
- Constant Field Values
-
EXPIRES_AT
public static final String EXPIRES_AT
- See Also:
- Constant Field Values
-
RS_256
public static final String RS_256
RSA 256 key algorithm- See Also:
- Constant Field Values
-
RS_384
public static final String RS_384
RSA 384 key algorithm- See Also:
- Constant Field Values
-
RS_512
public static final String RS_512
RSA 512 key algorithm- See Also:
- Constant Field Values
-
ES_256
public static final String ES_256
Elliptic curve ES 256 key algorithm- See Also:
- Constant Field Values
-
ES_256K
public static final String ES_256K
Elliptic curve ES 256K key algorithm- See Also:
- Constant Field Values
-
ES_384
public static final String ES_384
Elliptic curve ES 384 key algorithm- See Also:
- Constant Field Values
-
ES_512
public static final String ES_512
Elliptic curve ES 512 key algorithm- See Also:
- Constant Field Values
-
EC_CURVE_P_256
public static final String EC_CURVE_P_256
-
EC_CURVE_P_256K
public static final String EC_CURVE_P_256K
-
EC_CURVE_P_384
public static final String EC_CURVE_P_384
-
EC_CURVE_P_521
public static final String EC_CURVE_P_521
-
EC_CURVE_SEC_256K1
public static final String EC_CURVE_SEC_256K1
-
EC_CURVE_ED_25519
public static final String EC_CURVE_ED_25519
-
EC_CURVE_ED_448
public static final String EC_CURVE_ED_448
-
EC_CURVE_X_25519
public static final String EC_CURVE_X_25519
-
EC_CURVE_X_448
public static final String EC_CURVE_X_448
-
ALL_EC_CURVES
public static final String[] ALL_EC_CURVES
-
ALL_EC_ALGORITHMS
public static final String[] ALL_EC_ALGORITHMS
-
ALL_RSA_ALGORITHMS
public static final String[] ALL_RSA_ALGORITHMS
-
-
Method Detail
-
fromJSON
public JSONWebKeys fromJSON(File file) throws IOException
- Throws:
IOException
-
fromJSON
public JSONWebKeys fromJSON(String x)
-
fromJSON
public JSONWebKeys fromJSON(net.sf.json.JSON json)
-
getJsonWebKey
public JSONWebKey getJsonWebKey(net.sf.json.JSONObject json)
-
getJsonWebKey
public JSONWebKey getJsonWebKey(String rawJSON)
-
makePublic
public JSONWebKey makePublic(JSONWebKey key)
-
makePublic
public JSONWebKeys makePublic(JSONWebKeys keys)
-
toJSON
public net.sf.json.JSONObject toJSON(JSONWebKeys webKeys)
-
toJSON
public net.sf.json.JSONObject toJSON(JSONWebKey webKey)
-
initToJSON
protected static net.sf.json.JSONObject initToJSON(JSONWebKey webKey)
This creats a JSON object from theJSONWebKey
that serializes it in a spec compliant way, hence can be turned back into a JOSEJWK
.- Parameters:
webKey
-- Returns:
-
toJSONEC
protected net.sf.json.JSONObject toJSONEC(JSONWebKey webKey)
-
toJSONRSA
protected net.sf.json.JSONObject toJSONRSA(JSONWebKey webKey)
-
createECKey
public JSONWebKey createECKey() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Create a webkey using the given named curve. Currently supported names are- Ed25519
- Ed448
- P-256
- P-256K (deprecated, may be removed)
- P-384
- P-521
- X25519
- X448
- secp256k1
- Returns:
- Throws:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
createECKey
public JSONWebKey createECKey(String curveName, String alg) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
-
createRSAKey
public JSONWebKey createRSAKey(int length, String alg) throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
-
getIdLength
public int getIdLength()
-
setIdLength
public void setIdLength(int idLength)
-
createRSAKey
public JSONWebKey createRSAKey() throws NoSuchAlgorithmException, InvalidAlgorithmParameterException
Create and RSA key with the default bit size (2048) and RS256 algorithm.- Returns:
- Throws:
NoSuchAlgorithmException
InvalidAlgorithmParameterException
-
createID
protected String createID()
Create id with standard 8 byte length- Returns:
-
createID
protected String createID(int count)
-
bigIntToString
protected String bigIntToString(BigInteger bigInteger)
-
-