Java Key Create getKeyManagerFactory(KeyStore keystore, String password)

Here you can find the source of getKeyManagerFactory(KeyStore keystore, String password)

Description

Given a keystore and keystore password (as generated by #pemsToKeyAndTrustStores ), return a key manager factory that contains the keystore.

License

Apache License

Parameter

Parameter Description
keystore The keystore to get a key manager for
password The password for the keystore

Exception

Parameter Description
NoSuchAlgorithmException an exception
KeyStoreException an exception
UnrecoverableKeyException an exception

Return

A key manager factory for the provided keystore

Declaration

public static KeyManagerFactory getKeyManagerFactory(KeyStore keystore, String password)
        throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import javax.net.ssl.KeyManagerFactory;

import java.security.KeyStore;
import java.security.KeyStoreException;

import java.security.NoSuchAlgorithmException;

import java.security.UnrecoverableKeyException;

import java.util.Map;

public class Main {
    /**/*ww  w .  j a va  2 s. c  om*/
     * Given a keystore and keystore password (as generated by {@link #pemsToKeyAndTrustStores}),
     * return a key manager factory that contains the keystore.
     *
     * @param keystore The keystore to get a key manager for
     * @param password The password for the keystore
     * @return A key manager factory for the provided keystore
     * @throws NoSuchAlgorithmException
     * @throws KeyStoreException
     * @throws UnrecoverableKeyException
     */
    public static KeyManagerFactory getKeyManagerFactory(KeyStore keystore, String password)
            throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException {
        KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
        factory.init(keystore, password.toCharArray());
        return factory;
    }

    private static KeyManagerFactory getKeyManagerFactory(Map<String, Object> stores)
            throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException {
        KeyStore keystore = (KeyStore) stores.get("keystore");
        String password = (String) stores.get("keystore-pw");
        return getKeyManagerFactory(keystore, password);
    }
}

Related

  1. getKeyGenerator(String algorithm)
  2. getKeyKeyManagerFactory(InputStream keyStore, String password, String algorithm, String keyStoreType)
  3. getKeyKeyManagerFactoryByPfx(InputStream keyStore, String password)
  4. getKeyManager(KeyStore keyStore, char[] keyStorePassword)
  5. getKeyManagerFactory(InputStream key, String keyPassword)
  6. getKeyManagerFactory(KeyStore store, char[] password)
  7. getKeyManagerFactory(Map stores)
  8. getKeyManagers()
  9. getKeyManagers(KeyStore keyStore, String keyPassword)