private static KeyPair generateKeyPair() { try { return RSAKeys.generateKeyPair(); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } }
@Override protected void load() throws IOException { try { if (privateKeyFile.exists() && publicKeyFile.exists()) { privateKey = RSAKeys.fromPemEncodingToPrivateKey(FileUtils.readFileToString(privateKeyFile)); publicKey = RSAKeys.fromPemEncodingToPublicKey(FileUtils.readFileToString(publicKeyFile)); } else { KeyPair pair = RSAKeys.generateKeyPair(); privateKey = pair.getPrivate(); publicKey = pair.getPublic(); save(); } } catch (Exception e) { LOGGER.severe("Failed to load OAuth key pair: " + e.getMessage()); } }