*/
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 RSAPublicKeySpec publicKeySpec = new RSAPublicKeySpec(privateCrtKey.getPublicExponent()
, privateCrtKey.getModulus());
final KeyFactory keyFactory = KeyFactory.getInstance(privateCrtKey.getAlgorithm());
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) {