net.suberic.crypto
Interface EncryptionKeyManager


public interface EncryptionKeyManager

This manages a set of Encryption keys for use with PGP or S/MIME.


Method Summary
 boolean containsPrivateKeyAlias(java.lang.String alias)
          Checks if the given alias exists in this keystore.
 boolean containsPublicKeyAlias(java.lang.String alias)
          Checks if the given alias exists in this keystore.
 void deletePrivateKeyEntry(java.lang.String alias, char[] password)
          Deletes the entry identified by the given alias from this keystore.
 void deletePublicKeyEntry(java.lang.String alias)
          Deletes the entry identified by the given alias from this keystore.
 java.security.Key getPrivateKey(java.lang.String alias, char[] password)
          Returns the key associated with the given alias, using the given password to recover it.
 java.security.Key getPublicKey(java.lang.String alias)
          Returns the key associated with the given alias, using the given password to recover it.
 void loadPrivateKeystore(java.io.InputStream stream, char[] password)
           
 void loadPublicKeystore(java.io.InputStream stream, char[] password)
           
 java.util.Set privateKeyAliases()
          Lists all the alias names of this keystore.
 java.util.Set publicKeyAliases()
          Lists all the alias names of this keystore.
 void setPrivateKeyEntry(java.lang.String alias, java.security.Key key, char[] password)
          Assigns the given key to the given alias, protecting it with the given password.
 void setPublicKeyEntry(java.lang.String alias, java.security.Key key)
          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 storePrivateKeystore(java.io.OutputStream stream, char[] password)
          Stores this keystore to the given output stream, and protects its integrity with the given password.
 void storePublicKeystore(java.io.OutputStream stream, char[] password)
          Stores this keystore to the given output stream, and protects its integrity with the given password.
 

Method Detail

loadPublicKeystore

public void loadPublicKeystore(java.io.InputStream stream,
                               char[] password)
                        throws java.io.IOException,
                               java.security.NoSuchAlgorithmException,
                               java.security.KeyStoreException,
                               java.security.cert.CertificateException,
                               java.security.NoSuchProviderException
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.cert.CertificateException
java.security.NoSuchProviderException

loadPrivateKeystore

public void loadPrivateKeystore(java.io.InputStream stream,
                                char[] password)
                         throws java.io.IOException,
                                java.security.NoSuchAlgorithmException,
                                java.security.KeyStoreException,
                                java.security.NoSuchProviderException,
                                java.security.cert.CertificateException
Throws:
java.io.IOException
java.security.NoSuchAlgorithmException
java.security.KeyStoreException
java.security.NoSuchProviderException
java.security.cert.CertificateException

storePublicKeystore

public void storePublicKeystore(java.io.OutputStream stream,
                                char[] password)
                         throws java.io.IOException,
                                java.security.NoSuchAlgorithmException,
                                java.security.KeyStoreException,
                                java.security.cert.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
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).
java.io.IOException - if there was an I/O problem with data
java.security.NoSuchAlgorithmException - if the appropriate data integrity algorithm could not be found
java.security.cert.CertificateException

storePrivateKeystore

public void storePrivateKeystore(java.io.OutputStream stream,
                                 char[] password)
                          throws java.io.IOException,
                                 java.security.NoSuchAlgorithmException,
                                 java.security.KeyStoreException,
                                 java.security.cert.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
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).
java.io.IOException - if there was an I/O problem with data
java.security.NoSuchAlgorithmException - if the appropriate data integrity algorithm could not be found
java.security.cert.CertificateException

size

public int size()
         throws java.security.KeyStoreException
Retrieves the number of entries in this keystore.

Returns:
the number of entries in this keystore
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).

getPublicKey

public java.security.Key getPublicKey(java.lang.String alias)
                               throws java.security.KeyStoreException,
                                      java.security.NoSuchAlgorithmException,
                                      java.security.UnrecoverableKeyException
Returns the key associated with the given alias, using the given password to recover it.

Parameters:
alias - the alias name
Returns:
the requested key, or null if the given alias does not exist or does not identify a key entry.
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).
java.security.NoSuchAlgorithmException - if the algorithm for recovering the key cannot be found
java.security.UnrecoverableKeyException - if the key cannot be recovered (e.g., the given password is wrong).

getPrivateKey

public java.security.Key getPrivateKey(java.lang.String alias,
                                       char[] password)
                                throws java.security.KeyStoreException,
                                       java.security.NoSuchAlgorithmException,
                                       java.security.UnrecoverableKeyException
Returns the key associated with the given alias, using the given password to recover it.

Parameters:
alias - the alias name
password - the password for recovering the key
Returns:
the requested key, or null if the given alias does not exist or does not identify a key entry.
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).
java.security.NoSuchAlgorithmException - if the algorithm for recovering the key cannot be found
java.security.UnrecoverableKeyException - if the key cannot be recovered (e.g., the given password is wrong).

setPublicKeyEntry

public void setPublicKeyEntry(java.lang.String alias,
                              java.security.Key key)
                       throws java.security.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
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason

setPrivateKeyEntry

public void setPrivateKeyEntry(java.lang.String alias,
                               java.security.Key key,
                               char[] password)
                        throws java.security.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
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded), the given key cannot be protected, or this operation fails for some other reason

deletePublicKeyEntry

public void deletePublicKeyEntry(java.lang.String alias)
                          throws java.security.KeyStoreException
Deletes the entry identified by the given alias from this keystore.

Parameters:
alias - the alias name
Throws:
java.security.KeyStoreException - if the keystore has not been initialized, or if the entry cannot be removed.

deletePrivateKeyEntry

public void deletePrivateKeyEntry(java.lang.String alias,
                                  char[] password)
                           throws java.security.KeyStoreException
Deletes the entry identified by the given alias from this keystore.

Parameters:
alias - the alias name
Throws:
java.security.KeyStoreException - if the keystore has not been initialized, or if the entry cannot be removed.

publicKeyAliases

public java.util.Set publicKeyAliases()
                               throws java.security.KeyStoreException
Lists all the alias names of this keystore.

Returns:
set of the alias names
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).

privateKeyAliases

public java.util.Set privateKeyAliases()
                                throws java.security.KeyStoreException
Lists all the alias names of this keystore.

Returns:
set of the alias names
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).

containsPublicKeyAlias

public boolean containsPublicKeyAlias(java.lang.String alias)
                               throws java.security.KeyStoreException
Checks if the given alias exists in this keystore.

Parameters:
alias - the alias name
Returns:
true if the alias exists, false otherwise
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).

containsPrivateKeyAlias

public boolean containsPrivateKeyAlias(java.lang.String alias)
                                throws java.security.KeyStoreException
Checks if the given alias exists in this keystore.

Parameters:
alias - the alias name
Returns:
true if the alias exists, false otherwise
Throws:
java.security.KeyStoreException - if the keystore has not been initialized (loaded).