public class JWTUtil extends Object
Created by Jeff Gaynor
on 2/9/15 at 10:45 AM
Modifier and Type | Field and Description |
---|---|
static String |
ALGORITHM |
static int |
HEADER_INDEX |
static String |
ID_TOKKEN |
static String |
KEY_ID |
static String |
NONE_JWT |
static int |
NONE_KEY |
static int |
PAYLOAD_INDEX |
static String |
RS256_JAVA |
static String |
RS256_JWT |
static int |
RS256_KEY |
static String |
RS384_JAVA |
static String |
RS384_JWT |
static int |
RS384_KEY |
static String |
RS512_JAVA |
static String |
RS512_JWT |
static int |
RS512_KEY |
static int |
SIGNATURE_INDEX |
static String |
TYPE |
Constructor and Description |
---|
JWTUtil() |
Modifier and Type | Method and Description |
---|---|
protected static String |
concat(net.sf.json.JSONObject header,
net.sf.json.JSONObject payload) |
static String |
createJWT(net.sf.json.JSONObject payload)
Creates an unsigned token.
|
static String |
createJWT(net.sf.json.JSONObject payload,
JSONWebKey jsonWebKey) |
static String[] |
decat(String idToken)
This returns header, payload and signature as the three elements of an array.
|
static void |
firstTest() |
static void |
firstTestB() |
static void |
generateAndSign() |
protected static String |
getJavaSignatureName(String algorithm) |
static JSONWebKeys |
getJsonWebKeys(ServiceClient serviceClient,
String wellKnown) |
static JSONWebKeys |
getJsonWebKeys(String wellKnown)
Create a basic
ServiceClient to get the keys from the well known page. |
static JSONWebKeys |
getJsonWebKeys(URI wellKnown) |
static void |
main(String[] args)
Strictly for testing.
|
static void |
otherTest() |
static void |
printKeys() |
static net.sf.json.JSONObject[] |
readJWT(String jwt)
This will only peel off the header and payload.
|
protected static String |
sign(net.sf.json.JSONObject header,
net.sf.json.JSONObject payload,
JSONWebKey webkey) |
protected static String |
sign(String x,
JSONWebKey webkey) |
static void |
signAndVerify(JSONWebKeys keys,
String keyID) |
static void |
testJWT_IO() |
static void |
testSigning() |
static void |
testSigningDirectly() |
static boolean |
verify(net.sf.json.JSONObject header,
net.sf.json.JSONObject payload,
String sig,
JSONWebKey webKey) |
static net.sf.json.JSONObject |
verifyAndReadJWT(String jwt,
JSONWebKeys webKeys) |
static net.sf.json.JSONObject |
verifyAndReadJWT(String jwt,
URI wellKnown) |
public static String TYPE
public static String KEY_ID
public static String ALGORITHM
public static final String NONE_JWT
public static final int NONE_KEY
public static final String RS256_JWT
public static final String RS256_JAVA
public static final int RS256_KEY
public static final String RS384_JWT
public static final String RS384_JAVA
public static final int RS384_KEY
public static final String RS512_JWT
public static final String RS512_JAVA
public static final int RS512_KEY
public static final int HEADER_INDEX
public static final int PAYLOAD_INDEX
public static final int SIGNATURE_INDEX
public static String ID_TOKKEN
public static String createJWT(net.sf.json.JSONObject payload)
payload
- public static String createJWT(net.sf.json.JSONObject payload, JSONWebKey jsonWebKey) throws NoSuchAlgorithmException, SignatureException, InvalidKeySpecException, InvalidKeyException, IOException
protected static String concat(net.sf.json.JSONObject header, net.sf.json.JSONObject payload)
protected static String sign(net.sf.json.JSONObject header, net.sf.json.JSONObject payload, JSONWebKey webkey) throws IOException, InvalidKeySpecException, NoSuchAlgorithmException, InvalidKeyException, SignatureException
protected static String sign(String x, JSONWebKey webkey) throws InvalidKeyException, NoSuchAlgorithmException, InvalidKeySpecException, SignatureException
public static boolean verify(net.sf.json.JSONObject header, net.sf.json.JSONObject payload, String sig, JSONWebKey webKey) throws NoSuchAlgorithmException, InvalidKeyException, SignatureException, InvalidKeySpecException
public static String[] decat(String idToken)
idToken
- public static net.sf.json.JSONObject[] readJWT(String jwt)
jwt
- public static net.sf.json.JSONObject verifyAndReadJWT(String jwt, JSONWebKeys webKeys)
public static JSONWebKeys getJsonWebKeys(String wellKnown)
ServiceClient
to get the keys from the well known page. If you require a special
setup (e.g. your own SSL certs), you will need to create your own ServiceClient and supply that in the
related call getJSONWebKeys(ServiceClient, String wellKnown).wellKnown
- public static JSONWebKeys getJsonWebKeys(URI wellKnown)
public static JSONWebKeys getJsonWebKeys(ServiceClient serviceClient, String wellKnown)
public static void main(String[] args)
args
- public static void signAndVerify(JSONWebKeys keys, String keyID) throws Exception
Exception
Copyright © 2019. All Rights Reserved.