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_ALGORITHMSstatic String[]ALL_EC_CURVESstatic String[]ALL_RSA_ALGORITHMSstatic StringEC_CURVE_ED_25519static StringEC_CURVE_ED_448static StringEC_CURVE_KEYstatic StringEC_CURVE_P_256static StringEC_CURVE_P_256Kstatic StringEC_CURVE_P_384static StringEC_CURVE_P_521static StringEC_CURVE_SEC_256K1static StringEC_CURVE_X_25519static StringEC_CURVE_X_448static StringES_256Elliptic curve ES 256 key algorithmstatic StringES_256KElliptic curve ES 256K key algorithmstatic StringES_384Elliptic curve ES 384 key algorithmstatic StringES_512Elliptic curve ES 512 key algorithmstatic StringEXPIRES_ATstatic StringISSUED_ATstatic StringKEY_IDstatic StringKEY_TYPEstatic StringKEYSstatic StringNOT_VALID_BEFOREstatic StringRS_256RSA 256 key algorithmstatic StringRS_384RSA 384 key algorithmstatic StringRS_512RSA 512 key algorithmstatic StringUSE
-
Constructor Summary
Constructors Constructor Description JWKUtil2()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected StringbigIntToString(BigInteger bigInteger)JSONWebKeycreateECKey()Create a webkey using the given named curve.JSONWebKeycreateECKey(String curveName, String alg)protected StringcreateID()Create id with standard 8 byte lengthprotected StringcreateID(int count)JSONWebKeycreateRSAKey()Create and RSA key with the default bit size (2048) and RS256 algorithm.JSONWebKeycreateRSAKey(int length, String alg)JSONWebKeysfromJSON(File file)JSONWebKeysfromJSON(String x)JSONWebKeysfromJSON(net.sf.json.JSON json)intgetIdLength()JSONWebKeygetJsonWebKey(String rawJSON)JSONWebKeygetJsonWebKey(net.sf.json.JSONObject json)protected static net.sf.json.JSONObjectinitToJSON(JSONWebKey webKey)This creats a JSON object from theJSONWebKeythat serializes it in a spec compliant way, hence can be turned back into a JOSEJWK.JSONWebKeymakePublic(JSONWebKey key)JSONWebKeysmakePublic(JSONWebKeys keys)voidsetIdLength(int idLength)net.sf.json.JSONObjecttoJSON(JSONWebKey webKey)net.sf.json.JSONObjecttoJSON(JSONWebKeys webKeys)protected net.sf.json.JSONObjecttoJSONEC(JSONWebKey webKey)protected net.sf.json.JSONObjecttoJSONRSA(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 theJSONWebKeythat 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:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
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:
NoSuchAlgorithmExceptionInvalidAlgorithmParameterException
-
createID
protected String createID()
Create id with standard 8 byte length- Returns:
-
createID
protected String createID(int count)
-
bigIntToString
protected String bigIntToString(BigInteger bigInteger)
-
-