protected static String getPrivateKeyAlias(final KeyStore keyStore, final String keyStoreAlias) {
        try {
            val aliases = keyStore.aliases();
            while (aliases.hasMoreElements()) {
                val currentAlias = aliases.nextElement();
                if (keyStoreAlias != null) {
                    if (currentAlias.equalsIgnoreCase(keyStoreAlias)) {
                        return currentAlias;
                    }
                } else if (keyStore.entryInstanceOf(currentAlias, KeyStore.PrivateKeyEntry.class)) {
                    return currentAlias;
                }
            }
            throw new SAMLException("Keystore has no private keys to match the requested key alias " + keyStoreAlias);
        } catch (final KeyStoreException e) {
            throw new SAMLException("Unable to get aliases from keyStore", e);
        }
    }
Class responsible for loading a private key from a JKS keystore and returning
the corresponding {@link Credential} opensaml object.

@author Misagh Moayyed
@since 1.8.0
pac4j-saml/src/main/java/org/pac4j/saml/crypto/KeyStoreCredentialProvider.java