Final

java.security
Class KeyStore

java.lang.Object
  extended by java.security.KeyStore

public class KeyStore
extends Object


Constructor Summary
protected KeyStore(KeyStoreSpi keyStoreSpi, Provider provider, String type)
          Constructs a new instance of this class with the given keystore type.
 
Method Summary
 Enumeration aliases()
          Answers the alias names for the receiver.
 boolean containsAlias(String alias)
          Checks if the given alias exists in the receiver.
 void deleteEntry(String alias)
          Deletes as given alias entry from the receiver.
 Certificate getCertificate(String alias)
          Answers a certificate associated with the given alias.
 String getCertificateAlias(Certificate cert)
          Answers the alias for a given Certificate.
 Certificate[] getCertificateChain(String alias)
          Answers the Certificate chain associated with teh given alias.
 Date getCreationDate(String alias)
          Answers the creation date for the given alias.
static String getDefaultType()
          Answers the default keystore implementation type
static KeyStore getInstance(String type)
          Answers a new KeyStore of the given type.
static KeyStore getInstance(String type, Provider provider)
          Answers a new KeyStore of the given type.
static KeyStore getInstance(String type, String providerName)
          Answers a new KeyStore of the given type.
 Key getKey(String alias, char[] password)
          Answers the key associated with the given alias.
 Provider getProvider()
          Returns the Provider of the keystore represented by the receiver.
 String getType()
          Returns the keystore type
 boolean isCertificateEntry(String alias)
          Answers whether the alias entry represents a trusted certificate entry
 boolean isKeyEntry(String alias)
          Answers whether the alias entry represents a key entry
 void load(InputStream stream, char[] password)
          Loads the keystore from the given input stream, using the password provided.
 void setCertificateEntry(String alias, Certificate cert)
          Assigns a certificate to an alias
 void setKeyEntry(String alias, byte[] key, Certificate[] chain)
          Assigns the given key to an alias.
 void setKeyEntry(String alias, Key key, char[] password, Certificate[] chain)
          Assigns the given key to an alias.
 int size()
          Retrieves the number of entries in the keystore
 void store(OutputStream stream, char[] password)
          Stores the keystore into the given input stream, using the password provided.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

KeyStore

protected KeyStore(KeyStoreSpi keyStoreSpi,
                   Provider provider,
                   String type)
Constructs a new instance of this class with the given keystore type.

Parameters:
keyStoreSpi - KeyStoreSpi The actual keystore implementation
provider - Provider The provider of the key factory
type - String The keystore type
Method Detail

aliases

public final Enumeration aliases()
                          throws KeyStoreException
Answers the alias names for the receiver.

Returns:
Enumeration All alias names for the receiver
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

containsAlias

public final boolean containsAlias(String alias)
                            throws KeyStoreException
Checks if the given alias exists in the receiver.

Parameters:
alias - String The alias to be searched for.
Returns:
true if the alias exists, false otherwise
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

deleteEntry

public final void deleteEntry(String alias)
                       throws KeyStoreException
Deletes as given alias entry from the receiver.

Parameters:
alias - String The alias to be deleted.
Throws:
KeyStoreException - If the alias cannot be removed

getCertificate

public final Certificate getCertificate(String alias)
                                 throws KeyStoreException
Answers a certificate associated with the given alias.

Parameters:
alias - String The alias to be searched for.
Returns:
Certificate a certificate associated with the given alias.
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

getCertificateAlias

public final String getCertificateAlias(Certificate cert)
                                 throws KeyStoreException
Answers the alias for a given Certificate.

Parameters:
cert - Certificate The Certificate to be searched for.
Returns:
String The alias for the given Certificate, null if the alias does not exist or if the Certificate does not exist in the receiver.
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

getCertificateChain

public final Certificate[] getCertificateChain(String alias)
                                        throws KeyStoreException
Answers the Certificate chain associated with teh given alias.

Parameters:
alias - String The alias to be searched for.
Returns:
Certificate[] a chain of certificates associated with the given alias.
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

getCreationDate

public final Date getCreationDate(String alias)
                           throws KeyStoreException
Answers the creation date for the given alias.

Parameters:
alias - String The alias to be searched for.
Returns:
Date The date when the entry for this alias was created, null if the alias does not exist
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

getInstance

public static KeyStore getInstance(String type)
                            throws KeyStoreException
Answers a new KeyStore of the given type.

Parameters:
type - java.lang.String Type of keystore desired
Returns:
KeyStore a concrete implementation for the KeyStore type desired.
Throws:
KeyStoreException - If the type cannot be found

getInstance

public static KeyStore getInstance(String type,
                                   String providerName)
                            throws KeyStoreException,
                                   NoSuchProviderException
Answers a new KeyStore of the given type.

Parameters:
type - java.lang.String Type of keystore desired
providerName - java.lang.String Name of the provider which has to implement the algorithm
Returns:
KeyStore a concrete implementation for the KeyStore type desired.
Throws:
KeyStoreException - If the type cannot be found
NoSuchProviderException - If the provider cannot be found

getInstance

public static KeyStore getInstance(String type,
                                   Provider provider)
                            throws KeyStoreException
Answers a new KeyStore of the given type.

Parameters:
type - java.lang.String Type of keystore desired
provider - Provider Provider which has to implement the algorithm
Returns:
KeyStore a concrete implementation for the KeyStore type desired.
Throws:
KeyStoreException - If the type cannot be found

getKey

public final Key getKey(String alias,
                        char[] password)
                 throws KeyStoreException,
                        NoSuchAlgorithmException,
                        UnrecoverableKeyException
Answers the key associated with the given alias.

Parameters:
alias - String The alias to be searched for.
password - char[] Password to use when fetching the key for the alias
Returns:
Key key associated with the given alias, null if the alias does not exist
Throws:
KeyStoreException - If the keystore has not been initialized
NoSuchAlgorithmException - If the algorithm to recover the key cannot be found
UnrecoverableKeyException - If the key can't be recovered

getProvider

public final Provider getProvider()
Returns the Provider of the keystore represented by the receiver.

Returns:
Provider an instance of a subclass of java.security.Provider

getType

public final String getType()
Returns the keystore type

Returns:
String type of keystore being used

isCertificateEntry

public final boolean isCertificateEntry(String alias)
                                 throws KeyStoreException
Answers whether the alias entry represents a trusted certificate entry

Parameters:
alias - String The alias to be searched for.
Returns:
boolean true if the alias entry represents a trusted certificate entry, false otherwise
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

isKeyEntry

public final boolean isKeyEntry(String alias)
                         throws KeyStoreException
Answers whether the alias entry represents a key entry

Parameters:
alias - String The alias to be searched for.
Returns:
boolean true if the alias entry represents a key entry, false otherwise
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

load

public final void load(InputStream stream,
                       char[] password)
                throws IOException,
                       NoSuchAlgorithmException,
                       CertificateException
Loads the keystore from the given input stream, using the password provided.

Parameters:
stream - InputStream stream from where to read the keystore
password - char array representing password for the keystore
Throws:
IOException - An IO problem was found when reading the keystore
NoSuchAlgorithmException - The algorithm to check the integrity of the keystore cannot be found
CertificateException - If a certificate in the keystore could not be loaded.

setCertificateEntry

public final void setCertificateEntry(String alias,
                                      Certificate cert)
                               throws KeyStoreException
Assigns a certificate to an alias

Parameters:
alias - String an alias for the Certificate
cert - Certificate The Certificate for which an alias is being registered
Throws:
KeyStoreException - if the alias already exists for an untrusted Certificate

setKeyEntry

public final void setKeyEntry(String alias,
                              byte[] key,
                              Certificate[] chain)
                       throws KeyStoreException
Assigns the given key to an alias. If the key is a PrivateKey, a Certificate chain for the corresponding public key must be provided.

Parameters:
alias - String the alias name
key - byte[] key in protected format, to be associated with the alias
chain - Certificate[] chain of certificates for the corresponding public key
Throws:
KeyStoreException - if the operation fails

setKeyEntry

public final void setKeyEntry(String alias,
                              Key key,
                              char[] password,
                              Certificate[] chain)
                       throws KeyStoreException
Assigns the given key to an alias. If the key is a PrivateKey, a Certificate chain for the corresponding public key must be provided.

Parameters:
alias - String the alias name
key - Key key to be associated with the alias
password - char[] the passwrod to protect the key
chain - Certificate[] chain of certificates for the corresponding public key
Throws:
KeyStoreException - if the operation fails

size

public final int size()
               throws KeyStoreException
Retrieves the number of entries in the keystore

Returns:
int the number of entries in the keystore
Throws:
KeyStoreException - If the Keystore has not been initialized (loaded)

store

public final void store(OutputStream stream,
                        char[] password)
                 throws KeyStoreException,
                        IOException,
                        NoSuchAlgorithmException,
                        CertificateException
Stores the keystore into the given input stream, using the password provided.

Parameters:
stream - OutputStream stream from where to store the keystore
password -
Throws:
KeyStoreException - If the keystore has not been initialized
IOException - An IO problem was found when writing the keystore
NoSuchAlgorithmException - The data integrity algorithm for the keystore cannot be found
CertificateException - If a certificate in the keystore could not be stored.

getDefaultType

public static final String getDefaultType()
Answers the default keystore implementation type

Returns:
The default KeyStore implementation type

Final

Licensed Materials - Property of IBM
© Copyright IBM Corp. 2006, 2008 All Rights Reserved.