protected
KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
Creates a KeyStore object of the given type, and encapsulates the given provider implementation (SPI object) in it.
Enumeration<String>
aliases()
Lists all the alias names of this keystore.
boolean
containsAlias(String alias)
Checks if the given alias exists in this keystore.
void
deleteEntry(String alias)
Deletes the entry identified by the given alias from this keystore.
boolean
entryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass)
Determines if the keystore Entry
for the specified alias
is an instance or subclass of the specified entryClass
.
Certificate
getCertificate(String alias)
Returns the certificate associated with the given alias.
String
getCertificateAlias(Certificate cert)
Returns the (alias) name of the first keystore entry whose certificate matches the given certificate.
Certificate[]
getCertificateChain(String alias)
Returns the certificate chain associated with the given alias.
Date
getCreationDate(String alias)
Returns the creation date of the entry identified by the given alias.
static String
getDefaultType()
Returns the default keystore type as specified by the keystore.type
security property, or the string "jks" (acronym for "Java keystore") if no such property exists.
KeyStore.Entry
getEntry(String alias, KeyStore.ProtectionParameter protParam)
Gets a keystore Entry
for the specified alias with the specified protection parameter.
static KeyStore
getInstance(File file, char[] password)
Returns a loaded keystore object of the appropriate keystore type.
static KeyStore
getInstance(File file, KeyStore.LoadStoreParameter param)
Returns a loaded keystore object of the appropriate keystore type.
static KeyStore
getInstance(String type)
Returns a keystore object of the specified type.
static KeyStore
getInstance(String type, String provider)
Returns a keystore object of the specified type.
static KeyStore
getInstance(String type, Provider provider)
Returns a keystore object of the specified type.
Key
getKey(String alias, char[] password)
Returns the key associated with the given alias, using the given password to recover it.
Provider
getProvider()
Returns the provider of this keystore.
String
getType()
Returns the type of this keystore.
boolean
isCertificateEntry(String alias)
Returns true if the entry identified by the given alias was created by a call to setCertificateEntry
, or created by a call to setEntry
with a TrustedCertificateEntry
.
boolean
isKeyEntry(String alias)
Returns true if the entry identified by the given alias was created by a call to setKeyEntry
, or created by a call to setEntry
with a PrivateKeyEntry
or a SecretKeyEntry
.
void
load(InputStream stream, char[] password)
Loads this KeyStore from the given input stream.
void
load(KeyStore.LoadStoreParameter param)
Loads this keystore using the given LoadStoreParameter
.
void
setCertificateEntry(String alias, Certificate cert)
Assigns the given trusted certificate to the given alias.
void
setEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam)
Saves a keystore Entry
under the specified alias.
void
setKeyEntry(String alias, byte[] key, Certificate[] chain)
Assigns the given key (that has already been protected) to the given alias.
void
setKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
Assigns the given key to the given alias, protecting it with the given password.
int
size()
Retrieves the number of entries in this keystore.
void
store(OutputStream stream, char[] password)
Stores this keystore to the given output stream, and protects its integrity with the given password.
void
store(KeyStore.LoadStoreParameter param)
Stores this keystore using the given LoadStoreParameter
.
protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
Creates a KeyStore object of the given type, and encapsulates the given provider implementation (SPI object) in it.
keyStoreSpi
- the provider implementation.
provider
- the provider.
type
- the keystore type.
public static KeyStore getInstance(String type) throws KeyStoreException
Returns a keystore object of the specified type.
This method traverses the list of registered security Providers, starting with the most preferred Provider. A new KeyStore object encapsulating the KeyStoreSpi implementation 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.
jdk.security.provider.preferred
Security
property to determine the preferred provider order for the specified algorithm. This may be different than the order of providers returned by Security.getProviders()
.
type
- the type of keystore. See the KeyStore section in the Java Security Standard Algorithm Names Specification for information about standard keystore types.
KeyStoreException
- if no Provider
supports a KeyStoreSpi
implementation for the specified type
NullPointerException
- if type
is null
Provider
public static KeyStore getInstance(String type, String provider) throws KeyStoreException, NoSuchProviderException
Returns a keystore object of the specified type.
A new KeyStore object encapsulating the KeyStoreSpi implementation 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.
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.
IllegalArgumentException
- if the provider name is null
or empty
KeyStoreException
- if a KeyStoreSpi
implementation 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 type
is null
Provider
public static KeyStore getInstance(String type, Provider provider) throws KeyStoreException
A new KeyStore object encapsulating the KeyStoreSpi implementation from the specified Provider object is returned. Note that the specified Provider object does not have to be registered in the provider list.
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.
IllegalArgumentException
- if the specified provider is null
KeyStoreException
- if KeyStoreSpi
implementation for the specified type is not available from the specified Provider
object
NullPointerException
- if type
is null
Provider
public static final String getDefaultType()
Returns the default keystore type as specified by the
keystore.type
security property, or the string "jks" (acronym for "Java keystore") 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 getInstance
methods, 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.type
security property to the desired keystore type.
keystore.type
security property, or the string "jks" if no such property exists.
security properties
public final Provider getProvider()
Returns the provider of this keystore.
public final String getType()
Returns the type of this keystore.
public 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 to setKeyEntry
, or by a call to setEntry
with a PrivateKeyEntry
or SecretKeyEntry
.
alias
- the alias name
password
- the password for recovering the key
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).
public final Certificate[] getCertificateChain(String alias) throws KeyStoreException
Returns the certificate chain associated with the given alias. The certificate chain must have been associated with the alias by a call to setKeyEntry
, or by a call to setEntry
with a PrivateKeyEntry
.
alias
- the alias name
KeyStoreException
- if the keystore has not been initialized (loaded).
public final Certificate getCertificate(String alias) throws KeyStoreException
Returns 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 to setEntry
with a TrustedCertificateEntry
, 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 to setEntry
with a PrivateKeyEntry
, then the first element of the certificate chain in that entry is returned.
alias
- the alias name
KeyStoreException
- if the keystore has not been initialized (loaded).
public final Date getCreationDate(String alias) throws KeyStoreException
Returns the creation date of the entry identified by the given alias.
alias
- the alias name
KeyStoreException
- if the keystore has not been initialized (loaded).
public 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).
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
).
KeyStoreException
- if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason
public 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 type jks
, key
must be encoded as an EncryptedPrivateKeyInfo
as 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).
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
).
KeyStoreException
- if the keystore has not been initialized (loaded), or if this operation fails for some other reason.
public final void setCertificateEntry(String alias, Certificate cert) throws KeyStoreException
If the given alias identifies an existing entry created by a call to setCertificateEntry
, or created by a call to setEntry
with a TrustedCertificateEntry
, the trusted certificate in the existing entry is overridden by the given certificate.
alias
- the alias name
cert
- the certificate
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.
public final void deleteEntry(String alias) throws KeyStoreException
Deletes the entry identified by the given alias from this keystore.
alias
- the alias name
KeyStoreException
- if the keystore has not been initialized, or if the entry cannot be removed.
public final Enumeration<String> aliases() throws KeyStoreException
Lists all the alias names of this keystore.
KeyStoreException
- if the keystore has not been initialized (loaded).
public final boolean containsAlias(String alias) throws KeyStoreException
Checks if the given alias exists in this keystore.
alias
- the alias name
KeyStoreException
- if the keystore has not been initialized (loaded).
public final int size() throws KeyStoreException
Retrieves the number of entries in this keystore.
KeyStoreException
- if the keystore has not been initialized (loaded).
public final boolean isKeyEntry(String alias) throws KeyStoreException
Returns true if the entry identified by the given alias was created by a call to setKeyEntry
, or created by a call to setEntry
with a PrivateKeyEntry
or a SecretKeyEntry
.
alias
- the alias for the keystore entry to be checked
KeyStoreException
- if the keystore has not been initialized (loaded).
public final boolean isCertificateEntry(String alias) throws KeyStoreException
Returns true if the entry identified by the given alias was created by a call to setCertificateEntry
, or created by a call to setEntry
with a TrustedCertificateEntry
.
alias
- the alias for the keystore entry to be checked
KeyStoreException
- if the keystore has not been initialized (loaded).
public final String getCertificateAlias(Certificate cert) throws KeyStoreException
Returns 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 to setEntry
with a TrustedCertificateEntry
, 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 to setEntry
with a PrivateKeyEntry
, then the given certificate is compared to the first element of that entry's certificate chain.
cert
- the certificate to match with.
KeyStoreException
- if the keystore has not been initialized (loaded).
public 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.
stream
- the output stream to which this keystore is written.
password
- the password to generate the keystore integrity check
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
public final void store(KeyStore.LoadStoreParameter param) throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException
Stores this keystore using the given LoadStoreParameter
.
param
- the LoadStoreParameter
that specifies how to store the keystore, which may be null
IllegalArgumentException
- if the given LoadStoreParameter
input 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
public 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 null
as the stream
argument.
Note that if this keystore has already been loaded, it is reinitialized and loaded again from the given input stream.
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
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 cause
of the IOException
should 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
public final void load(KeyStore.LoadStoreParameter param) throws IOException, NoSuchAlgorithmException, CertificateException
Loads this keystore using the given
LoadStoreParameter
.
Note that if this KeyStore has already been loaded, it is reinitialized and loaded again from the given parameter.
param
- the LoadStoreParameter
that specifies how to load the keystore, which may be null
IllegalArgumentException
- if the given LoadStoreParameter
input 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 cause
of the IOException
should 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
public final KeyStore.Entry getEntry(String alias, KeyStore.ProtectionParameter protParam) throws NoSuchAlgorithmException, UnrecoverableEntryException, KeyStoreException
Gets a keystore Entry
for the specified alias with the specified protection parameter.
alias
- get the keystore Entry
for this alias
protParam
- the ProtectionParameter
used to protect the Entry
, which may be null
Entry
for the specified alias, or null
if there is no such entry
NullPointerException
- if alias
is null
NoSuchAlgorithmException
- if the algorithm for recovering the entry cannot be found
UnrecoverableEntryException
- if the specified protParam
were insufficient or invalid
UnrecoverableKeyException
- if the entry is a PrivateKeyEntry
or SecretKeyEntry
and the specified protParam
does not contain the information needed to recover the key (e.g. wrong password)
KeyStoreException
- if the keystore has not been initialized (loaded).
setEntry(String, KeyStore.Entry, KeyStore.ProtectionParameter)
public final void setEntry(String alias, KeyStore.Entry entry, KeyStore.ProtectionParameter protParam) throws KeyStoreException
Saves a keystore
Entry
under the specified alias. The protection parameter is used to protect the
Entry
.
If an entry already exists for the specified alias, it is overridden.
alias
- save the keystore Entry
under this alias
entry
- the Entry
to save
protParam
- the ProtectionParameter
used to protect the Entry
, which may be null
NullPointerException
- if alias
or entry
is null
KeyStoreException
- if the keystore has not been initialized (loaded), or if this operation fails for some other reason
getEntry(String, KeyStore.ProtectionParameter)
public final boolean entryInstanceOf(String alias, Class<? extends KeyStore.Entry> entryClass) throws KeyStoreException
Determines if the keystore Entry
for the specified alias
is an instance or subclass of the specified entryClass
.
alias
- the alias name
entryClass
- the entry class
Entry
for the specified alias
is an instance or subclass of the specified entryClass
, false otherwise
NullPointerException
- if alias
or entryClass
is null
KeyStoreException
- if the keystore has not been initialized (loaded)
public 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 KeyStoreSpi
implementation supported by a Provider, it invokes the engineProbe
method to determine if it supports the specified keystore. A new KeyStore object is returned that encapsulates the KeyStoreSpi implementation from the first Provider that supports the specified file.
Note that the list of registered providers may be retrieved via the Security.getProviders()
method.
file
- the keystore file
password
- the keystore password, which may be null
KeyStoreException
- if no Provider supports a KeyStoreSpi implementation 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 cause
of the IOException
should 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.
Provider
public 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. A
LoadStoreParameter
may 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 KeyStoreSpi
implementation supported by a Provider, it invokes the engineProbe
method to determine if it supports the specified keystore. A new KeyStore object is returned that encapsulates the KeyStoreSpi implementation from the first Provider that supports the specified file.
Note that the list of registered providers may be retrieved via the Security.getProviders()
method.
file
- the keystore file
param
- the LoadStoreParameter
that specifies how to load the keystore, which may be null
KeyStoreException
- if no Provider supports a KeyStoreSpi implementation 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 cause
of the IOException
should 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.
Provider
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4