Search in sources :

Example 1 with JSONWebKey

use of edu.uiuc.ncsa.security.util.jwk.JSONWebKey in project OA4MP by ncsa.

the class SciTokensCommands method list_key_ids.

public void list_key_ids(InputLine inputLine) throws Exception {
    if (showHelp(inputLine)) {
        printListKeyIDs();
        return;
    }
    JSONWebKeys jsonWebKeys = null;
    if (1 < inputLine.size()) {
        jsonWebKeys = JSONWebKeyUtil.fromJSON(new File(inputLine.getArg(1)));
    } else {
        if (keys == null) {
            if (getBooleanInput("Do you want to enter a file name?")) {
                String x = getInput("Enter path and name of the key file");
                jsonWebKeys = JSONWebKeyUtil.fromJSON(new File(x));
            } else {
                return;
            }
        } else {
            jsonWebKeys = keys;
        }
    }
    String defaultWebKey = null;
    if (jsonWebKeys.hasDefaultKey()) {
        defaultWebKey = jsonWebKeys.getDefaultKeyID();
    } else {
        defaultWebKey = defaultKeyID;
    }
    for (String keyID : jsonWebKeys.keySet()) {
        JSONWebKey webKey = jsonWebKeys.get(keyID);
        boolean isDefault = webKey.id.equals(defaultWebKey);
        say("id=" + keyID + ", alg=" + webKey.algorithm + ", type=" + webKey.type + ", use=" + webKey.use + (isDefault ? " (default)" : ""));
    }
}
Also used : JSONWebKey(edu.uiuc.ncsa.security.util.jwk.JSONWebKey) JSONWebKeys(edu.uiuc.ncsa.security.util.jwk.JSONWebKeys) File(java.io.File)

Example 2 with JSONWebKey

use of edu.uiuc.ncsa.security.util.jwk.JSONWebKey in project OA4MP by ncsa.

the class SigningCommands method createJWK.

protected JSONWebKey createJWK(String algorithm) throws NoSuchProviderException, NoSuchAlgorithmException {
    byte[] byteArray = new byte[16];
    random.nextBytes(byteArray);
    String id = DatatypeConverter.printHexBinary(byteArray);
    KeyPair keyPair = KeyUtil.generateKeyPair();
    JSONWebKey webKey = new JSONWebKey();
    webKey.publicKey = keyPair.getPublic();
    webKey.privateKey = keyPair.getPrivate();
    webKey.use = "sig";
    webKey.id = id;
    webKey.algorithm = algorithm;
    // only one supported
    webKey.type = "RSA";
    return webKey;
}
Also used : KeyPair(java.security.KeyPair) JSONWebKey(edu.uiuc.ncsa.security.util.jwk.JSONWebKey)

Aggregations

JSONWebKey (edu.uiuc.ncsa.security.util.jwk.JSONWebKey)2 JSONWebKeys (edu.uiuc.ncsa.security.util.jwk.JSONWebKeys)1 File (java.io.File)1 KeyPair (java.security.KeyPair)1