use of org.forgerock.openam.shared.security.crypto.KeyStoreBuilder in project OpenAM by OpenRock.
the class AuthenticatorOathService method getEncryptionKeyPair.
private KeyPair getEncryptionKeyPair() {
try {
final KeyStore keyStore = new KeyStoreBuilder().withKeyStoreFile(new File(CollectionHelper.getMapAttr(options, OATH_KEYSTORE_FILE))).withPassword(CollectionHelper.getMapAttr(options, OATH_KEYSTORE_PASSWORD)).withKeyStoreType(KeyStoreType.valueOf(CollectionHelper.getMapAttr(options, OATH_KEYSTORE_TYPE))).build();
final Certificate cert = keyStore.getCertificate(CollectionHelper.getMapAttr(options, OATH_KEYSTORE_KEYPAIR_ALIAS));
final PublicKey publicKey = cert.getPublicKey();
final PrivateKey privateKey = (PrivateKey) keyStore.getKey(CollectionHelper.getMapAttr(options, OATH_KEYSTORE_KEYPAIR_ALIAS), CollectionHelper.getMapAttr(options, OATH_KEYSTORE_PRIVATEKEY_PASSWORD).toCharArray());
return new KeyPair(publicKey, privateKey);
} catch (FileNotFoundException e) {
throw new IllegalArgumentException("Invalid keystore location specified", e);
} catch (KeyStoreException | UnrecoverableKeyException | NoSuchAlgorithmException e) {
debug.error("AuthenticatorOathService.getEncryptionKeyPair(): Unable to load encryption key pair", e);
throw new IllegalStateException(e);
}
}
Aggregations