use of edu.uiuc.ncsa.security.util.jwk.JSONWebKeys in project OA4MP by ncsa.
the class SigningCommands method create.
public void create(InputLine inputLine) throws Exception {
if (showHelp(inputLine)) {
createHelp();
return;
}
// PublicKey publicKey = KeyUtil.g
boolean retry = true;
File publicKeyFile = null;
boolean isInteractive = true;
if (1 < inputLine.size()) {
publicKeyFile = new File(inputLine.getArg(1));
}
if (publicKeyFile == null && isBatchMode()) {
throw new GeneralException("No full path to the file given.");
}
while (retry) {
String publicKeyPath = getInput("Give the file path", "");
if (publicKeyPath.toLowerCase().equals("exit") || publicKeyPath.toLowerCase().equals("quit")) {
return;
}
publicKeyFile = new File(publicKeyPath);
if (publicKeyFile.exists()) {
if (!publicKeyFile.isFile()) {
sayi("Sorry, but you must supply the name of the file as well (or type 'exit' to exit");
} else {
sayi2("The file you gave exists, do you want to over write it? [y/n]");
retry = !isOk(readline());
}
} else {
retry = false;
}
}
retry = true;
sayi2("create a new set of JSON web keys?[y/n]");
if (!isOk(readline())) {
say("create cancelled.");
return;
}
JSONWebKeys keys = new JSONWebKeys(null);
keys.put(createJWK("RS256"));
keys.put(createJWK("RS384"));
keys.put(createJWK("RS512"));
FileWriter writer = new FileWriter(publicKeyFile);
JSONObject jwks = JSONWebKeyUtil.toJSON(keys);
writer.write(jwks.toString(3));
writer.flush();
writer.close();
if (isInteractive) {
sayi("JSONweb keys written");
sayi("Done!");
}
}
Aggregations