A KeyStore manages different types of entries.
 Each type of entry implements the KeyStore.Entry interface.
 Three basic KeyStore.Entry implementations are provided:
 
- KeyStore.PrivateKeyEntry
 This type of entry holds a cryptographic PrivateKey, which is optionally stored in a protected format to prevent unauthorized access. It is also accompanied by a certificate chain for the corresponding public key.Private keys and certificate chains are used by a given entity for self-authentication. Applications for this authentication include software distribution organizations which sign JAR files as part of releasing and/or licensing software. 
- KeyStore.SecretKeyEntry
 This type of entry holds a cryptographic SecretKey, which is optionally stored in a protected format to prevent unauthorized access.
- KeyStore.TrustedCertificateEntry
 This type of entry contains a single public key Certificatebelonging to another party. It is called a trusted certificate because the keystore owner trusts that the public key in the certificate indeed belongs to the identity identified by the subject (owner) of the certificate.This type of entry can be used to authenticate other parties. 
Each entry in a keystore is identified by an "alias" string. In the case of private keys and their associated certificate chains, these strings distinguish among the different ways in which the entity may authenticate itself. For example, the entity may authenticate itself using different certificate authorities, or using different public key algorithms.
Whether aliases are case-sensitive is implementation dependent. In order to avoid problems, it is recommended not to use aliases in a KeyStore that only differ in case.
Whether keystores are persistent, and the mechanisms used by the keystore if it is persistent, are not specified here. This allows use of a variety of techniques for protecting sensitive (e.g., private or secret) keys. Smart cards or other integrated cryptographic engines (SafeKeyper) are one option, and simpler mechanisms such as files may also be used (in a variety of formats).
 Typical ways to request a KeyStore object include
 specifying an existing keystore file,
 relying on the default type and providing a specific keystore type.
 
- To specify an existing keystore file:
 // get keystore password char[] password = getPassword(); // probe the keystore file and load the keystore entries KeyStore ks = KeyStore.getInstance(new File("keyStoreName"), password);The system will probe the specified file to determine its keystore type and return a keystore implementation with its entries already loaded. When this approach is used there is no need to call the keystore'sloadmethod.
- To rely on the default type:
 KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());The system will return a keystore implementation for the default type.
- To provide a specific keystore type:
 KeyStore ks = KeyStore.getInstance("JKS");The system will return the most preferred implementation of the specified keystore type available in the environment.
 Before a keystore can be accessed, it must be
 loaded
 (unless it was already loaded during instantiation).
 
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());
    // get user password and file input stream
    char[] password = getPassword();
    try (FileInputStream fis = new FileInputStream("keyStoreName")) {
        ks.load(fis, password);
    }
 
 To create an empty keystore using the above load method,
 pass null as the InputStream argument.
 Once the keystore has been loaded, it is possible to read existing entries from the keystore, or to write new entries into the keystore:
    KeyStore.PasswordProtection protParam =
        new KeyStore.PasswordProtection(password);
    try (FileOutputStream fos = new FileOutputStream("newKeyStoreName")) {
        // get my private key
        KeyStore.PrivateKeyEntry pkEntry = (KeyStore.PrivateKeyEntry)
            ks.getEntry("privateKeyAlias", protParam);
        PrivateKey myPrivateKey = pkEntry.getPrivateKey();
        // save my secret key
        javax.crypto.SecretKey mySecretKey;
        KeyStore.SecretKeyEntry skEntry =
            new KeyStore.SecretKeyEntry(mySecretKey);
        ks.setEntry("secretKeyAlias", skEntry, protParam);
        // store away the keystore
        ks.store(fos, password);
    } finally {
        protParam.destroy();
    }
 
 Note that although the same password may be used to
 load the keystore, to protect the private key entry,
 to protect the secret key entry, and to store the keystore
 (as is shown in the sample code above),
 different passwords or other protection parameters
 may also be used.
  Every implementation of the Java platform is required to support
 the following standard KeyStore type:
 
- PKCS12
- Since:
- 1.2
- See Also:
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classA description of a to-be-instantiatedKeyStoreobject.static classAProtectionParameterencapsulating a CallbackHandler.static interfaceA marker interface forKeyStoreentry types.static interfacestatic classA password-based implementation ofProtectionParameter.static final classAKeyStoreentry that holds aPrivateKeyand corresponding certificate chain.static interfaceA marker interface for keystore protection parameters.static final classAKeyStoreentry that holds aSecretKey.static final classAKeyStoreentry that holds a trustedCertificate.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedKeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type) Creates aKeyStoreobject of the given type, and encapsulates the given provider implementation (SPI object) in it.
- 
Method SummaryModifier and TypeMethodDescriptionfinal Enumeration<String> aliases()Lists all the alias names of this keystore.final booleancontainsAlias(String alias) Checks if the given alias exists in this keystore.final voiddeleteEntry(String alias) Deletes the entry identified by the given alias from this keystore.final booleanentryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass) Determines if the keystoreEntryfor the specifiedaliasis an instance or subclass of the specifiedentryClass.final Set<KeyStore.Entry.Attribute> getAttributes(String alias) Retrieves the attributes associated with the given alias.final CertificategetCertificate(String alias) Returns the certificate associated with the given alias.final StringReturns the (alias) name of the first keystore entry whose certificate matches the given certificate.final Certificate[]getCertificateChain(String alias) Returns the certificate chain associated with the given alias.final DategetCreationDate(String alias) Returns the creation date of the entry identified by the given alias.static final StringReturns the default keystore type as specified by thekeystore.typesecurity property, or the string "pkcs12" if no such property exists.final KeyStore.EntrygetEntry(String alias, KeyStore.ProtectionParameter protParam) Gets a keystoreEntryfor the specified alias with the specified protection parameter.static final KeyStoregetInstance(File file, char[] password) Returns a loaded keystore object of the appropriate keystore type.static final KeyStoregetInstance(File file, KeyStore.LoadStoreParameter param) Returns a loaded keystore object of the appropriate keystore type.static KeyStoregetInstance(String type) Returns aKeyStoreobject of the specified type.static KeyStoregetInstance(String type, String provider) Returns aKeyStoreobject of the specified type.static KeyStoregetInstance(String type, Provider provider) Returns aKeyStoreobject of the specified type.final KeyReturns the key associated with the given alias, using the given password to recover it.final ProviderReturns the provider of this keystore.final StringgetType()Returns the type of this keystore.final booleanisCertificateEntry(String alias) Returnstrueif the entry identified by the given alias was created by a call tosetCertificateEntry, or created by a call tosetEntrywith aTrustedCertificateEntry.final booleanisKeyEntry(String alias) Returnstrueif the entry identified by the given alias was created by a call tosetKeyEntry, or created by a call tosetEntrywith aPrivateKeyEntryor aSecretKeyEntry.final voidload(InputStream stream, char[] password) Loads this keystore from the given input stream.final voidload(KeyStore.LoadStoreParameter param) Loads this keystore using the givenLoadStoreParameter.final voidsetCertificateEntry(String alias, Certificate cert) Assigns the given trusted certificate to the given alias.final voidsetEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) Saves a keystoreEntryunder the specified alias.final voidsetKeyEntry(String alias, byte[] key, Certificate[] chain) Assigns the given key (that has already been protected) to the given alias.final voidsetKeyEntry(String alias, Key key, char[] password, Certificate[] chain) Assigns the given key to the given alias, protecting it with the given password.final intsize()Retrieves the number of entries in this keystore.final voidstore(OutputStream stream, char[] password) Stores this keystore to the given output stream, and protects its integrity with the given password.final voidstore(KeyStore.LoadStoreParameter param) Stores this keystore using the givenLoadStoreParameter.
- 
Constructor Details- 
KeyStoreCreates aKeyStoreobject of the given type, and encapsulates the given provider implementation (SPI object) in it.- Parameters:
- keyStoreSpi- the provider implementation.
- provider- the provider.
- type- the keystore type.
 
 
- 
- 
Method Details- 
getInstanceReturns aKeyStoreobject of the specified type.This method traverses the list of registered security providers, starting with the most preferred provider. A new KeyStoreobject encapsulating theKeyStoreSpiimplementation from the first provider that supports the specified type is returned.Note that the list of registered providers may be retrieved via the Security.getProviders()method.- Implementation Note:
- The JDK Reference Implementation additionally uses the
 jdk.security.provider.preferredSecurityproperty to determine the preferred provider order for the specified algorithm. This may be different from the order of providers returned bySecurity.getProviders().
- Parameters:
- type- the type of keystore. See the KeyStore section in the Java Security Standard Algorithm Names Specification for information about standard keystore types.
- Returns:
- a keystore object of the specified type
- Throws:
- KeyStoreException- if no provider supports a- KeyStoreSpiimplementation for the specified type
- NullPointerException- if- typeis- null
- See Also:
 
- 
getInstancepublic static KeyStore getInstance(String type, String provider) throws KeyStoreException, NoSuchProviderException Returns aKeyStoreobject of the specified type.A new KeyStoreobject encapsulating theKeyStoreSpiimplementation from the specified provider is returned. The specified provider must be registered in the security provider list.Note that the list of registered providers may be retrieved via the Security.getProviders()method.- Parameters:
- type- the type of keystore. See the KeyStore section in the Java Security Standard Algorithm Names Specification for information about standard keystore types.
- provider- the name of the provider.
- Returns:
- a keystore object of the specified type
- Throws:
- IllegalArgumentException- if the provider name is- nullor empty
- KeyStoreException- if a- KeyStoreSpiimplementation for the specified type is not available from the specified provider
- NoSuchProviderException- if the specified provider is not registered in the security provider list
- NullPointerException- if- typeis- null
- See Also:
 
- 
getInstanceReturns aKeyStoreobject of the specified type.A new KeyStoreobject encapsulating theKeyStoreSpiimplementation from the specified provider object is returned. Note that the specified provider object does not have to be registered in the provider list.- Parameters:
- type- the type of keystore. See the KeyStore section in the Java Security Standard Algorithm Names Specification for information about standard keystore types.
- provider- the provider.
- Returns:
- a keystore object of the specified type
- Throws:
- IllegalArgumentException- if the specified provider is- null
- KeyStoreException- if- KeyStoreSpiimplementation for the specified type is not available from the specified- Providerobject
- NullPointerException- if- typeis- null
- Since:
- 1.4
- See Also:
 
- 
getDefaultTypeReturns the default keystore type as specified by thekeystore.typesecurity property, or the string "pkcs12" if no such property exists.The default keystore type can be used by applications that do not want to use a hard-coded keystore type when calling one of the getInstancemethods, and want to provide a default keystore type in case a user does not specify its own.The default keystore type can be changed by setting the value of the keystore.typesecurity property to the desired keystore type.- Returns:
- the default keystore type as specified by the
 keystore.typesecurity property, or the string "pkcs12" if no such property exists.
- See Also:
 
- 
getProviderReturns the provider of this keystore.- Returns:
- the provider of this keystore.
 
- 
getTypeReturns the type of this keystore.- Returns:
- the type of this keystore.
 
- 
getAttributesRetrieves the attributes associated with the given alias.- Parameters:
- alias- the alias name
- Returns:
- an unmodifiable Setof attributes. This set is empty if theKeyStoreSpiimplementation has not overriddenKeyStoreSpi.engineGetAttributes(String), or the given alias does not exist, or there are no attributes associated with the alias. This set may also be empty forPrivateKeyEntryorSecretKeyEntryentries that contain protected attributes and are only available through theKeyStore.Entry.getAttributes()method after the entry is extracted.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
- NullPointerException- if- aliasis- null
- Since:
- 18
 
- 
getKeypublic final Key getKey(String alias, char[] password) throws KeyStoreException, NoSuchAlgorithmException, UnrecoverableKeyException Returns the key associated with the given alias, using the given password to recover it. The key must have been associated with the alias by a call tosetKeyEntry, or by a call tosetEntrywith aPrivateKeyEntryorSecretKeyEntry.- Parameters:
- alias- the alias name
- password- the password for recovering the key
- Returns:
- the requested key, or nullif the given alias does not exist or does not identify a key-related entry.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
- NoSuchAlgorithmException- if the algorithm for recovering the key cannot be found
- UnrecoverableKeyException- if the key cannot be recovered (e.g., the given password is wrong).
 
- 
getCertificateChainReturns the certificate chain associated with the given alias. The certificate chain must have been associated with the alias by a call tosetKeyEntry, or by a call tosetEntrywith aPrivateKeyEntry.- Parameters:
- alias- the alias name
- Returns:
- the certificate chain (ordered with the user's certificate first
 followed by zero or more certificate authorities), or nullif the given alias does not exist or does not contain a certificate chain
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
getCertificateReturns the certificate associated with the given alias.If the given alias name identifies an entry created by a call to setCertificateEntry, or created by a call tosetEntrywith aTrustedCertificateEntry, then the trusted certificate contained in that entry is returned.If the given alias name identifies an entry created by a call to setKeyEntry, or created by a call tosetEntrywith aPrivateKeyEntry, then the first element of the certificate chain in that entry is returned.- Parameters:
- alias- the alias name
- Returns:
- the certificate, or nullif the given alias does not exist or does not contain a certificate.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
getCreationDateReturns the creation date of the entry identified by the given alias.- Parameters:
- alias- the alias name
- Returns:
- the creation date of this entry, or nullif the given alias does not exist
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
setKeyEntrypublic final void setKeyEntry(String alias, Key key, char[] password, Certificate[] chain) throws KeyStoreException Assigns the given key to the given alias, protecting it with the given password.If the given key is of type java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key.If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain). - Parameters:
- alias- the alias name
- key- the key to be associated with the alias
- password- the password to protect the key
- chain- the certificate chain for the corresponding public key (only required if the given key is of type- java.security.PrivateKey).
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason
 
- 
setKeyEntrypublic final void setKeyEntry(String alias, byte[] key, Certificate[] chain) throws KeyStoreException Assigns the given key (that has already been protected) to the given alias.If the protected key is of type java.security.PrivateKey, it must be accompanied by a certificate chain certifying the corresponding public key. If the underlying keystore implementation is of typejks,keymust be encoded as anEncryptedPrivateKeyInfoas defined in the PKCS #8 standard.If the given alias already exists, the keystore information associated with it is overridden by the given key (and possibly certificate chain). - Parameters:
- alias- the alias name
- key- the key (in protected format) to be associated with the alias
- chain- the certificate chain for the corresponding public key (only useful if the protected key is of type- java.security.PrivateKey).
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded), or if this operation fails for some other reason.
 
- 
setCertificateEntryAssigns the given trusted certificate to the given alias.If the given alias identifies an existing entry created by a call to setCertificateEntry, or created by a call tosetEntrywith aTrustedCertificateEntry, the trusted certificate in the existing entry is overridden by the given certificate.- Parameters:
- alias- the alias name
- cert- the certificate
- Throws:
- KeyStoreException- if the keystore has not been initialized, or the given alias already exists and does not identify an entry containing a trusted certificate, or this operation fails for some other reason.
 
- 
deleteEntryDeletes the entry identified by the given alias from this keystore.- Parameters:
- alias- the alias name
- Throws:
- KeyStoreException- if the keystore has not been initialized, or if the entry cannot be removed.
 
- 
aliasesLists all the alias names of this keystore.- Returns:
- enumeration of the alias names
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
containsAliasChecks if the given alias exists in this keystore.- Parameters:
- alias- the alias name
- Returns:
- trueif the alias exists,- falseotherwise
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
sizeRetrieves the number of entries in this keystore.- Returns:
- the number of entries in this keystore
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
isKeyEntryReturnstrueif the entry identified by the given alias was created by a call tosetKeyEntry, or created by a call tosetEntrywith aPrivateKeyEntryor aSecretKeyEntry.- Parameters:
- alias- the alias for the keystore entry to be checked
- Returns:
- trueif the entry identified by the given alias is a key-related entry,- falseotherwise.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
isCertificateEntryReturnstrueif the entry identified by the given alias was created by a call tosetCertificateEntry, or created by a call tosetEntrywith aTrustedCertificateEntry.- Parameters:
- alias- the alias for the keystore entry to be checked
- Returns:
- trueif the entry identified by the given alias contains a trusted certificate,- falseotherwise.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
getCertificateAliasReturns the (alias) name of the first keystore entry whose certificate matches the given certificate.This method attempts to match the given certificate with each keystore entry. If the entry being considered was created by a call to setCertificateEntry, or created by a call tosetEntrywith aTrustedCertificateEntry, then the given certificate is compared to that entry's certificate.If the entry being considered was created by a call to setKeyEntry, or created by a call tosetEntrywith aPrivateKeyEntry, then the given certificate is compared to the first element of that entry's certificate chain.- Parameters:
- cert- the certificate to match with.
- Returns:
- the alias name of the first entry with a matching certificate,
 or nullif no such entry exists in this keystore.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
 
- 
storepublic final void store(OutputStream stream, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException Stores this keystore to the given output stream, and protects its integrity with the given password.- Parameters:
- stream- the output stream to which this keystore is written.
- password- the password to generate the keystore integrity check. May be- nullif the keystore does not support or require an integrity check.
- Throws:
- KeyStoreException- if the keystore has not been initialized (loaded).
- IOException- if there was an I/O problem with data
- NoSuchAlgorithmException- if the appropriate data integrity algorithm could not be found
- CertificateException- if any of the certificates included in the keystore data could not be stored
 
- 
storepublic final void store(KeyStore.LoadStoreParameter param) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException Stores this keystore using the givenLoadStoreParameter.- Parameters:
- param- the- LoadStoreParameterthat specifies how to store the keystore, which may be- null
- Throws:
- IllegalArgumentException- if the given- LoadStoreParameterinput is not recognized
- KeyStoreException- if the keystore has not been initialized (loaded)
- IOException- if there was an I/O problem with data
- NoSuchAlgorithmException- if the appropriate data integrity algorithm could not be found
- CertificateException- if any of the certificates included in the keystore data could not be stored
- UnsupportedOperationException- if this operation is not supported
- Since:
- 1.5
 
- 
loadpublic final void load(InputStream stream, char[] password) throws IOException, NoSuchAlgorithmException, CertificateException Loads this keystore from the given input stream.A password may be given to unlock the keystore (e.g. the keystore resides on a hardware token device), or to check the integrity of the keystore data. If a password is not given for integrity checking, then integrity checking is not performed. In order to create an empty keystore, or if the keystore cannot be initialized from a stream, pass nullas thestreamargument.Note that if this keystore has already been loaded, it is reinitialized and loaded again from the given input stream. - Parameters:
- stream- the input stream from which the keystore is loaded, or- null
- password- the password used to check the integrity of the keystore, the password used to unlock the keystore, or- null
- Throws:
- IOException- if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the- causeof the- IOExceptionshould be an- UnrecoverableKeyException
- NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be found
- CertificateException- if any of the certificates in the keystore could not be loaded
 
- 
loadpublic final void load(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException Loads this keystore using the givenLoadStoreParameter.Note that if this KeyStorehas already been loaded, it is reinitialized and loaded again from the given parameter.- Parameters:
- param- the- LoadStoreParameterthat specifies how to load the keystore, which may be- null
- Throws:
- IllegalArgumentException- if the given- LoadStoreParameterinput is not recognized
- IOException- if there is an I/O or format problem with the keystore data. If the error is due to an incorrect- ProtectionParameter(e.g. wrong password) the- causeof the- IOExceptionshould be an- UnrecoverableKeyException
- NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be found
- CertificateException- if any of the certificates in the keystore could not be loaded
- Since:
- 1.5
 
- 
getEntrypublic final KeyStore.Entry getEntry(String alias, KeyStore.ProtectionParameter protParam) throws NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException Gets a keystoreEntryfor the specified alias with the specified protection parameter.- Parameters:
- alias- get the keystore- Entryfor this alias
- protParam- the- ProtectionParameterused to protect the- Entry, which may be- null
- Returns:
- the keystore Entryfor the specified alias, ornullif there is no such entry
- Throws:
- NullPointerException- if- aliasis- null
- NoSuchAlgorithmException- if the algorithm for recovering the entry cannot be found
- UnrecoverableEntryException- if the specified- protParamwere insufficient or invalid
- UnrecoverableKeyException- if the entry is a- PrivateKeyEntryor- SecretKeyEntryand the specified- protParamdoes not contain the information needed to recover the key (e.g. wrong password)
- KeyStoreException- if the keystore has not been initialized (loaded).
- Since:
- 1.5
- See Also:
 
- 
setEntrypublic final void setEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException Saves a keystoreEntryunder the specified alias. The protection parameter is used to protect theEntry.If an entry already exists for the specified alias, it is overridden. - Parameters:
- alias- save the keystore- Entryunder this alias
- entry- the- Entryto save
- protParam- the- ProtectionParameterused to protect the- Entry, which may be- null
- Throws:
- NullPointerException- if- aliasor- entryis- null
- KeyStoreException- if the keystore has not been initialized (loaded), or if this operation fails for some other reason
- Since:
- 1.5
- See Also:
 
- 
entryInstanceOfpublic final boolean entryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass) throws KeyStoreException Determines if the keystoreEntryfor the specifiedaliasis an instance or subclass of the specifiedentryClass.- Parameters:
- alias- the alias name
- entryClass- the entry class
- Returns:
- trueif the keystore- Entryfor the specified- aliasis an instance or subclass of the specified- entryClass,- falseotherwise
- Throws:
- NullPointerException- if- aliasor- entryClassis- null
- KeyStoreException- if the keystore has not been initialized (loaded)
- Since:
- 1.5
 
- 
getInstancepublic static final KeyStore getInstance(File file, char[] password) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException Returns a loaded keystore object of the appropriate keystore type. First the keystore type is determined by probing the specified file. Then a keystore object is instantiated and loaded using the data from that file.A password may be given to unlock the keystore (e.g. the keystore resides on a hardware token device), or to check the integrity of the keystore data. If a password is not given for integrity checking, then integrity checking is not performed. This method traverses the list of registered security providers, starting with the most preferred provider. For each KeyStoreSpiimplementation supported by a provider, it invokes theengineProbemethod to determine if it supports the specified keystore. A newKeyStoreobject is returned that encapsulates theKeyStoreSpiimplementation from the first provider that supports the specified file.Note that the list of registered providers may be retrieved via the Security.getProviders()method.- Parameters:
- file- the keystore file
- password- the keystore password, which may be- null
- Returns:
- a keystore object loaded with keystore data
- Throws:
- KeyStoreException- if no provider supports a- KeyStoreSpiimplementation for the specified keystore file.
- IOException- if there is an I/O or format problem with the keystore data, if a password is required but not given, or if the given password was incorrect. If the error is due to a wrong password, the- causeof the- IOExceptionshould be an- UnrecoverableKeyException.
- NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be found.
- CertificateException- if any of the certificates in the keystore could not be loaded.
- IllegalArgumentException- if file does not exist or does not refer to a normal file.
- NullPointerException- if file is- null.
- SecurityException- if a security manager exists and its- SecurityManager.checkRead(java.io.FileDescriptor)method denies read access to the specified file.
- Since:
- 9
- See Also:
 
- 
getInstancepublic static final KeyStore getInstance(File file, KeyStore.LoadStoreParameter param) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException Returns a loaded keystore object of the appropriate keystore type. First the keystore type is determined by probing the specified file. Then a keystore object is instantiated and loaded using the data from that file. ALoadStoreParametermay be supplied which specifies how to unlock the keystore data or perform an integrity check.This method traverses the list of registered security providers, starting with the most preferred provider. For each KeyStoreSpiimplementation supported by a provider, it invokes theengineProbemethod to determine if it supports the specified keystore. A newKeyStoreobject is returned that encapsulates theKeyStoreSpiimplementation from the first provider that supports the specified file.Note that the list of registered providers may be retrieved via the Security.getProviders()method.- Parameters:
- file- the keystore file
- param- the- LoadStoreParameterthat specifies how to load the keystore, which may be- null
- Returns:
- a keystore object loaded with keystore data
- Throws:
- KeyStoreException- if no provider supports a- KeyStoreSpiimplementation for the specified keystore file.
- IOException- if there is an I/O or format problem with the keystore data. If the error is due to an incorrect- ProtectionParameter(e.g. wrong password) the- causeof the- IOExceptionshould be an- UnrecoverableKeyException.
- NoSuchAlgorithmException- if the algorithm used to check the integrity of the keystore cannot be found.
- CertificateException- if any of the certificates in the keystore could not be loaded.
- IllegalArgumentException- if file does not exist or does not refer to a normal file, or if param is not recognized.
- NullPointerException- if file is- null.
- SecurityException- if a security manager exists and its- SecurityManager.checkRead(java.io.FileDescriptor)method denies read access to the specified file.
- Since:
- 9
- See Also:
 
 
-