if (algorithm == null) {
throw new IllegalStateException("Could not read key pair algorithm");
}
if (privateKeyText.length() > 0) {
PemReader reader = new PemReader(new StringReader(privateKeyText.toString()));
PemObject obj = reader.readPemObject();
reader.close();
PrivateKeyInfo privateKeyInfo = new PrivateKeyInfo(new AlgorithmIdentifier(PKCSObjectIdentifiers.rsaEncryption, null), RSAPrivateKey.getInstance(obj.getContent()));
byte[] encoded = privateKeyInfo.getEncoded();
privateKey = Keys.getPrivateKeyFromPKCS8File(encoded, KeyPairType.RSA);
}
if (publicKeyText.length() > 0) {
PemReader reader = new PemReader(new StringReader(publicKeyText.toString()));
PemObject obj = reader.readPemObject();
reader.close();
byte[] publicKeyBytes = obj.getContent();
publicKey = Keys.getPublicKeyFromX509File(publicKeyBytes, KeyPairType.RSA);
}