Package com.norconex.commons.lang.security

# Class KeyStoreBuilder

java.lang.Object
com.norconex.commons.lang.security.KeyStoreBuilder

public final class KeyStoreBuilder extends Object
Builder for creating a KeyStore.

Since:
  2.0.0

- ## Method Summary

  Modifier and Type
  Method
  Description
  `KeyStore`
  `create()`
  Creates the key store.
  `static KeyStoreBuilder`
  `empty()`
  A builder for an empty key store.
  `static KeyStoreBuilder`
  `fromFile(Path file)`
  A builder for a key store initialized from a key store file.
  `static KeyStoreBuilder`
  `fromJavaHome()`
  A builder for a key store initialized from `{JAVA_HOME}/lib/security/cacerts`.
  `KeyStoreBuilder`
  `setPassword(String password)`
  Sets the key store password.
  `KeyStoreBuilder`
  `setPasswordKey(EncryptionKey passwordKey)`
  Sets the password encryption key.
  `KeyStoreBuilder`
  `setProvider(String provider)`
  Sets the security provider name.
  `KeyStoreBuilder`
  `setType(String type)`
  Sets the key store type.

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

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

- ## Method Details

  - ### setProvider

    public KeyStoreBuilder setProvider(String provider)
    Sets the security provider name. When not set, uses default provider for the key store type.
    Parameters:
      `provider` - provider name
    Returns:
      this builder

  - ### setType

    public KeyStoreBuilder setType(String type)
    Sets the key store type. When not set, uses default key store type.
    Parameters:
      `type` - key store type
    Returns:
      this builder

  - ### setPassword

    public KeyStoreBuilder setPassword(String password)
    Sets the key store password. When not set, it is assumed the key store does not require any password.
    Parameters:
      `password` - key store password.
    Returns:
      this builder

  - ### setPasswordKey

    public KeyStoreBuilder setPasswordKey(EncryptionKey passwordKey)
    Sets the password encryption key. In case the password is encrypted.
    Parameters:
      `passwordKey` - password key
    Returns:
      this builder
    See Also:
      - `EncryptionKey`

  - ### create

    public KeyStore create() throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException, NoSuchProviderException
    Creates the key store.
    Returns:
      key store
    Throws:
      `NoSuchAlgorithmException` - problem creating key store
      `CertificateException` - problem creating key store
      `IOException` - problem creating key store
      `KeyStoreException` - problem creating key store
      `NoSuchProviderException` - problem creating key store

  - ### fromJavaHome

    public static KeyStoreBuilder fromJavaHome()
    A builder for a key store initialized from `{JAVA_HOME}/lib/security/cacerts`.
    Returns:
      a key store builder

  - ### fromFile

    public static KeyStoreBuilder fromFile(Path file)
    A builder for a key store initialized from a key store file.
    Parameters:
      `file` - key store file
    Returns:
      a key store builder

  - ### empty

    public static KeyStoreBuilder empty()
    A builder for an empty key store.
    Returns:
      a key store builder