KeyStore.Builder (Java SE 9 & JDK 9 ) (original) (raw)
- java.security.KeyStore.Builder
Enclosing class:
KeyStore
public abstract static class KeyStore.Builder
extends Object
A description of a to-be-instantiated KeyStore object.
An instance of this class encapsulates the information needed to instantiate and initialize a KeyStore object. That process is triggered when the getKeyStore() method is called.
This makes it possible to decouple configuration from KeyStore object creation and e.g. delay a password prompt until it is needed.
Since:
1.5
See Also:
KeyStore, KeyStoreBuilderParameters
Constructor Summary
Constructors
Modifier Constructor Description protected Builder() Construct a new Builder. Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
Modifier and Type Method Description abstract KeyStore getKeyStore() Returns the KeyStore described by this object. abstract KeyStore.ProtectionParameter getProtectionParameter(String alias) Returns the ProtectionParameters that should be used to obtain the Entry with the given alias. static KeyStore.Builder newInstance(File file,KeyStore.ProtectionParameter protection) Returns a new Builder object. static KeyStore.Builder newInstance(String type,Provider provider,File file,KeyStore.ProtectionParameter protection) Returns a new Builder object. static KeyStore.Builder newInstance(String type,Provider provider,KeyStore.ProtectionParameter protection) Returns a new Builder object. static KeyStore.Builder newInstance(KeyStore keyStore,KeyStore.ProtectionParameter protectionParameter) Returns a new Builder that encapsulates the given KeyStore. * ### Methods inherited from class java.lang.[Object](../../java/lang/Object.html "class in java.lang") `[clone](../../java/lang/Object.html#clone--), [equals](../../java/lang/Object.html#equals-java.lang.Object-), [finalize](../../java/lang/Object.html#finalize--), [getClass](../../java/lang/Object.html#getClass--), [hashCode](../../java/lang/Object.html#hashCode--), [notify](../../java/lang/Object.html#notify--), [notifyAll](../../java/lang/Object.html#notifyAll--), [toString](../../java/lang/Object.html#toString--), [wait](../../java/lang/Object.html#wait--), [wait](../../java/lang/Object.html#wait-long-), [wait](../../java/lang/Object.html#wait-long-int-)`
Constructor Detail
* #### Builder protected Builder() Construct a new Builder.
Method Detail
* #### getKeyStore public abstract [KeyStore](../../java/security/KeyStore.html "class in java.security") getKeyStore() throws [KeyStoreException](../../java/security/KeyStoreException.html "class in java.security") Returns the KeyStore described by this object. Returns: the `KeyStore` described by this object Throws: `[KeyStoreException](../../java/security/KeyStoreException.html "class in java.security")` \- if an error occurred during the operation, for example if the KeyStore could not be instantiated or loaded * #### getProtectionParameter public abstract [KeyStore.ProtectionParameter](../../java/security/KeyStore.ProtectionParameter.html "interface in java.security") getProtectionParameter([String](../../java/lang/String.html "class in java.lang") alias) throws [KeyStoreException](../../java/security/KeyStoreException.html "class in java.security") Returns the ProtectionParameters that should be used to obtain the [Entry](../../java/security/KeyStore.Entry.html "interface in java.security") with the given alias. The `getKeyStore` method must be invoked before this method may be called. Parameters: `alias` \- the alias of the KeyStore entry Returns: the ProtectionParameters that should be used to obtain the [Entry](../../java/security/KeyStore.Entry.html "interface in java.security") with the given alias. Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if alias is null `[KeyStoreException](../../java/security/KeyStoreException.html "class in java.security")` \- if an error occurred during the operation `[IllegalStateException](../../java/lang/IllegalStateException.html "class in java.lang")` \- if the getKeyStore method has not been invoked prior to calling this method * #### newInstance public static [KeyStore.Builder](../../java/security/KeyStore.Builder.html "class in java.security") newInstance([KeyStore](../../java/security/KeyStore.html "class in java.security") keyStore, [KeyStore.ProtectionParameter](../../java/security/KeyStore.ProtectionParameter.html "interface in java.security") protectionParameter) Returns a new Builder that encapsulates the given KeyStore. The [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method of the returned object will return `keyStore`, the [getProtectionParameter()](../../java/security/KeyStore.Builder.html#getProtectionParameter-java.lang.String-) method will return `protectionParameters`. This is useful if an existing KeyStore object needs to be used with Builder-based APIs. Parameters: `keyStore` \- the KeyStore to be encapsulated `protectionParameter` \- the ProtectionParameter used to protect the KeyStore entries Returns: a new Builder object Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if keyStore or protectionParameters is null `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if the keyStore has not been initialized * #### newInstance public static [KeyStore.Builder](../../java/security/KeyStore.Builder.html "class in java.security") newInstance([String](../../java/lang/String.html "class in java.lang") type, [Provider](../../java/security/Provider.html "class in java.security") provider, [File](../../java/io/File.html "class in java.io") file, [KeyStore.ProtectionParameter](../../java/security/KeyStore.ProtectionParameter.html "interface in java.security") protection) Returns a new Builder object. The first call to the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method on the returned builder will create a KeyStore of type `type` and call its [load()](../../java/security/KeyStore.html#load-java.io.InputStream-char:A-) method. The `inputStream` argument is constructed from`file`. If `protection` is a`PasswordProtection`, the password is obtained by calling the `getPassword` method. Otherwise, if `protection` is a`CallbackHandlerProtection`, the password is obtained by invoking the CallbackHandler. Subsequent calls to [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) return the same object as the initial call. If the initial call failed with a KeyStoreException, subsequent calls also throw a KeyStoreException. The KeyStore is instantiated from `provider` if non-null. Otherwise, all installed providers are searched. Calls to [getProtectionParameter()](../../java/security/KeyStore.Builder.html#getProtectionParameter-java.lang.String-) will return a [PasswordProtection](../../java/security/KeyStore.PasswordProtection.html "class in java.security") object encapsulating the password that was used to invoke the`load` method. _Note_ that the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method is executed within the [AccessControlContext](../../java/security/AccessControlContext.html "class in java.security") of the code invoking this method. Parameters: `type` \- the type of KeyStore to be constructed `provider` \- the provider from which the KeyStore is to be instantiated (or null) `file` \- the File that contains the KeyStore data `protection` \- the ProtectionParameter securing the KeyStore data Returns: a new Builder object Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if type, file or protection is null `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if protection is not an instance of either PasswordProtection or CallbackHandlerProtection; or if file does not exist or does not refer to a normal file * #### newInstance public static [KeyStore.Builder](../../java/security/KeyStore.Builder.html "class in java.security") newInstance([File](../../java/io/File.html "class in java.io") file, [KeyStore.ProtectionParameter](../../java/security/KeyStore.ProtectionParameter.html "interface in java.security") protection) Returns a new Builder object. The first call to the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method on the returned builder will create a KeyStore using `file` to detect the keystore type and then call its [load()](../../java/security/KeyStore.html#load-java.io.InputStream-char:A-) method. It uses the same algorithm to determine the keystore type as described in [KeyStore.getInstance(File, LoadStoreParameter)](../../java/security/KeyStore.html#getInstance-java.io.File-java.security.KeyStore.LoadStoreParameter-). The `inputStream` argument is constructed from `file`. If `protection` is a `PasswordProtection`, the password is obtained by calling the `getPassword` method. Otherwise, if `protection` is a`CallbackHandlerProtection`, the password is obtained by invoking the CallbackHandler. Subsequent calls to [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) return the same object as the initial call. If the initial call failed with a KeyStoreException, subsequent calls also throw a KeyStoreException. Calls to [getProtectionParameter()](../../java/security/KeyStore.Builder.html#getProtectionParameter-java.lang.String-) will return a [PasswordProtection](../../java/security/KeyStore.PasswordProtection.html "class in java.security") object encapsulating the password that was used to invoke the`load` method. _Note_ that the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method is executed within the [AccessControlContext](../../java/security/AccessControlContext.html "class in java.security") of the code invoking this method. Parameters: `file` \- the File that contains the KeyStore data `protection` \- the ProtectionParameter securing the KeyStore data Returns: a new Builder object Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if file or protection is null `[IllegalArgumentException](../../java/lang/IllegalArgumentException.html "class in java.lang")` \- if protection is not an instance of either PasswordProtection or CallbackHandlerProtection; or if file does not exist or does not refer to a normal file Since: 9 * #### newInstance public static [KeyStore.Builder](../../java/security/KeyStore.Builder.html "class in java.security") newInstance([String](../../java/lang/String.html "class in java.lang") type, [Provider](../../java/security/Provider.html "class in java.security") provider, [KeyStore.ProtectionParameter](../../java/security/KeyStore.ProtectionParameter.html "interface in java.security") protection) Returns a new Builder object. Each call to the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method on the returned builder will return a new KeyStore object of type `type`. Its [load()](../../java/security/KeyStore.html#load-java.security.KeyStore.LoadStoreParameter-) method is invoked using a`LoadStoreParameter` that encapsulates`protection`. The KeyStore is instantiated from `provider` if non-null. Otherwise, all installed providers are searched. Calls to [getProtectionParameter()](../../java/security/KeyStore.Builder.html#getProtectionParameter-java.lang.String-) will return `protection`. _Note_ that the [getKeyStore()](../../java/security/KeyStore.Builder.html#getKeyStore--) method is executed within the [AccessControlContext](../../java/security/AccessControlContext.html "class in java.security") of the code invoking this method. Parameters: `type` \- the type of KeyStore to be constructed `provider` \- the provider from which the KeyStore is to be instantiated (or null) `protection` \- the ProtectionParameter securing the Keystore Returns: a new Builder object Throws: `[NullPointerException](../../java/lang/NullPointerException.html "class in java.lang")` \- if type or protection is null
Report a bug or suggest an enhancement
For further API reference and developer documentation see the Java SE Documentation, which contains more detailed, developer-targeted descriptions with conceptual overviews, definitions of terms, workarounds, and working code examples.
Java is a trademark or registered trademark of Oracle and/or its affiliates in the US and other countries.
Copyright © 1993, 2017, Oracle and/or its affiliates, 500 Oracle Parkway, Redwood Shores, CA 94065 USA.
All rights reserved. Use is subject to license terms and the documentation redistribution policy.