*/
private KeyPair getKeyPair() {
try {
final Reader pemFileReader = new FileReader(pemFile);
try {
final PEMReader pemReader;
if (pemPassword == null) {
pemReader = new PEMReader(pemFileReader);
} else {
final PasswordFinder passwordFinder = new CRXPasswordFinder(pemPassword);
pemReader = new PEMReader(pemFileReader, passwordFinder);
}
try {
final Object pemObject = pemReader.readObject();
if (pemObject instanceof KeyPair) {
return (KeyPair)pemObject;
} else if (pemObject instanceof RSAPrivateCrtKey) {
final RSAPrivateCrtKey privateCrtKey = (RSAPrivateCrtKey)pemObject;
final BigInteger exponent = privateCrtKey.getPublicExponent();
final BigInteger modulus = privateCrtKey.getModulus();
final RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(modulus, exponent);
final KeyFactory keyFactory = KeyFactory.getInstance("RSA", "BC");
final PublicKey publicKey = keyFactory.generatePublic(publicKeySpec);
return new KeyPair(publicKey, privateCrtKey);
} else {
throw new ArchiverException("Could not load the public/private key from invalid PEM file");
}
} finally {
pemReader.close();
}
} finally {
pemFileReader.close();
}
} catch (final InvalidKeySpecException e) {