KeyManagerUtils
Date: 2016-06-23

org.apache.commons.net.util

## Class KeyManagerUtils

- java.lang.Object
- - org.apache.commons.net.util.KeyManagerUtils

-     public final class KeyManagerUtils
      extends java.lang.Object

  General KeyManager utilities

  How to use with a client certificate:

       KeyManager km = KeyManagerUtils.createClientKeyManager("JKS",
           "/path/to/privatekeystore.jks","storepassword",
           "privatekeyalias", "keypassword");
       FTPSClient cl = new FTPSClient();
       cl.setKeyManager(km);
       cl.connect(...);

  If using the default store type and the key password is the same as the store password, these parameters can be omitted.
  If the desired key is the first or only key in the keystore, the keyAlias parameter can be omitted, in which case the code becomes:

       KeyManager km = KeyManagerUtils.createClientKeyManager(
           "/path/to/privatekeystore.jks","storepassword");
       FTPSClient cl = new FTPSClient();
       cl.setKeyManager(km);
       cl.connect(...);

  Since:
    3.0

- - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static javax.net.ssl.KeyManager` | `createClientKeyManager(java.io.File storePath, java.lang.String storePass)` Create a client key manager which returns a particular key.
    `static javax.net.ssl.KeyManager` | `createClientKeyManager(java.io.File storePath, java.lang.String storePass, java.lang.String keyAlias)` Create a client key manager which returns a particular key.
    `static javax.net.ssl.KeyManager` | `createClientKeyManager(java.security.KeyStore ks, java.lang.String keyAlias, java.lang.String keyPass)` Create a client key manager which returns a particular key.
    `static javax.net.ssl.KeyManager` | `createClientKeyManager(java.lang.String storeType, java.io.File storePath, java.lang.String storePass, java.lang.String keyAlias, java.lang.String keyPass)` Create a client key manager which returns a particular key.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Method Detail

    - #### createClientKeyManager

          public static javax.net.ssl.KeyManager createClientKeyManager(java.security.KeyStore ks,
                                                        java.lang.String keyAlias,
                                                        java.lang.String keyPass)
                                                                 throws java.security.GeneralSecurityException

      Create a client key manager which returns a particular key. Does not handle server keys.
      Parameters:
        `ks` - the keystore to use
        `keyAlias` - the alias of the key to use, may be `null` in which case the first key entry alias is used
        `keyPass` - the password of the key to use
      Returns:
        the customised KeyManager
      Throws:
        `java.security.GeneralSecurityException` - if there is a problem creating the keystore

    - #### createClientKeyManager

          public static javax.net.ssl.KeyManager createClientKeyManager(java.lang.String storeType,
                                                        java.io.File storePath,
                                                        java.lang.String storePass,
                                                        java.lang.String keyAlias,
                                                        java.lang.String keyPass)
                                                                 throws java.io.IOException,
                                                                        java.security.GeneralSecurityException

      Create a client key manager which returns a particular key. Does not handle server keys.
      Parameters:
        `storeType` - the type of the keyStore, e.g. "JKS"
        `storePath` - the path to the keyStore
        `storePass` - the keyStore password
        `keyAlias` - the alias of the key to use, may be `null` in which case the first key entry alias is used
        `keyPass` - the password of the key to use
      Returns:
        the customised KeyManager
      Throws:
        `java.security.GeneralSecurityException` - if there is a problem creating the keystore
        `java.io.IOException` - if there is a problem creating the keystore

    - #### createClientKeyManager

          public static javax.net.ssl.KeyManager createClientKeyManager(java.io.File storePath,
                                                        java.lang.String storePass,
                                                        java.lang.String keyAlias)
                                                                 throws java.io.IOException,
                                                                        java.security.GeneralSecurityException

      Create a client key manager which returns a particular key. Does not handle server keys. Uses the default store type and assumes the key password is the same as the store password
      Parameters:
        `storePath` - the path to the keyStore
        `storePass` - the keyStore password
        `keyAlias` - the alias of the key to use, may be `null` in which case the first key entry alias is used
      Returns:
        the customised KeyManager
      Throws:
        `java.io.IOException` - if there is a problem creating the keystore
        `java.security.GeneralSecurityException` - if there is a problem creating the keystore

    - #### createClientKeyManager

          public static javax.net.ssl.KeyManager createClientKeyManager(java.io.File storePath,
                                                        java.lang.String storePass)
                                                                 throws java.io.IOException,
                                                                        java.security.GeneralSecurityException

      Create a client key manager which returns a particular key. Does not handle server keys. Uses the default store type and assumes the key password is the same as the store password. The key alias is found by searching the keystore for the first private key entry
      Parameters:
        `storePath` - the path to the keyStore
        `storePass` - the keyStore password
      Returns:
        the customised KeyManager
      Throws:
        `java.io.IOException` - if there is a problem creating the keystore
        `java.security.GeneralSecurityException` - if there is a problem creating the keystore