org.neuclear.commons.crypto.signers
Class JCESigner

java.lang.Object
  extended by org.neuclear.commons.crypto.signers.JCESigner
All Implemented Interfaces:
BrowsableSigner, PublicKeySource, Signer
Direct Known Subclasses:
TestCaseSigner

public class JCESigner
extends java.lang.Object
implements BrowsableSigner

Wrapper around JCE KeyStore


Field Summary
 
Fields inherited from interface org.neuclear.commons.crypto.signers.Signer
KEY_DSA, KEY_NONE, KEY_OTHER, KEY_RSA
 
Constructor Summary
  JCESigner(java.security.KeyStore ks, PassPhraseAgent agent)
          Creates a signer based on a fully loaded keystore
protected JCESigner(java.lang.String name, java.io.InputStream in, java.lang.String type, java.lang.String provider, PassPhraseAgent agent)
          Constructs a JCESigner using the agent to provide the initial passphrase
protected JCESigner(java.lang.String name, java.io.InputStream in, java.lang.String type, java.lang.String provider, PassPhraseAgent agent, char[] initpassphrase)
          Constructs a JCESigner using the provided Initial passphrase to load the keystore
  JCESigner(java.lang.String filename, java.lang.String type, java.lang.String provider, PassPhraseAgent agent)
          Constructs a JCESigner with the agent providing the keystore passphrase.
  JCESigner(java.lang.String filename, java.lang.String type, java.lang.String provider, PassPhraseAgent agent, char[] initialpassphrase)
          Constructs a JCESigner providing a initial passphrase in the parameters.
 
Method Summary
 boolean canSignFor(java.lang.String name)
          Returns true if the Signer contains a signer for the given name
 void createKeyPair(java.lang.String alias, char[] passphrase)
           
 java.security.PublicKey generateKey()
          Creates a new KeyPair, stores the PrivateKey using the base32 sha1 of the public key as it's alias and returns the PublicKey.
 java.security.PublicKey generateKey(java.lang.String alias)
          Creates a new KeyPair, stores the PrivateKey using the given alias and returns the PublicKey.
 int getKeyType(java.lang.String name)
          Checks the key type of the given alias
 java.security.PublicKey getPublicKey(java.lang.String name)
           
 java.util.Iterator iterator()
           
 void save()
           
 void save(java.lang.String filename)
           
 void save(java.lang.String filename, char[] passphrase)
           
 byte[] sign(byte[] data, SetPublicKeyCallBack callback)
           
 byte[] sign(java.lang.String name, byte[] data)
          Signs the data with the privatekey of the given name
 byte[] sign(java.lang.String name, byte[] data, boolean incorrect)
           
 byte[] sign(java.lang.String name, char[] pass, byte[] data, SetPublicKeyCallBack callback)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JCESigner

public JCESigner(java.lang.String filename,
                 java.lang.String type,
                 java.lang.String provider,
                 PassPhraseAgent agent)
          throws UserCancellationException,
                 InvalidPassphraseException
Constructs a JCESigner with the agent providing the keystore passphrase.

Parameters:
filename -
type -
provider -
agent -
Throws:
InvalidPassphraseException - If the given passphrase is incorrect
UserCancellationException - If the user choses to cancel the process in the passphrase agent, this should cancel the loading process

JCESigner

public JCESigner(java.lang.String filename,
                 java.lang.String type,
                 java.lang.String provider,
                 PassPhraseAgent agent,
                 char[] initialpassphrase)
          throws InvalidPassphraseException
Constructs a JCESigner providing a initial passphrase in the parameters.

Parameters:
filename -
type -
provider -
agent -
initialpassphrase -
Throws:
InvalidPassphraseException - If the given passphrase is incorrect

JCESigner

protected JCESigner(java.lang.String name,
                    java.io.InputStream in,
                    java.lang.String type,
                    java.lang.String provider,
                    PassPhraseAgent agent)
             throws UserCancellationException,
                    InvalidPassphraseException
Constructs a JCESigner using the agent to provide the initial passphrase

Parameters:
name -
in -
type -
provider -
agent -
Throws:
InvalidPassphraseException - If the given passphrase is incorrect
UserCancellationException - If the user choses to cancel the process in the passphrase agent, this should cancel the loading process

JCESigner

protected JCESigner(java.lang.String name,
                    java.io.InputStream in,
                    java.lang.String type,
                    java.lang.String provider,
                    PassPhraseAgent agent,
                    char[] initpassphrase)
             throws InvalidPassphraseException
Constructs a JCESigner using the provided Initial passphrase to load the keystore

Parameters:
name -
in -
type -
provider -
agent -
initpassphrase -
Throws:
InvalidPassphraseException - If the given passphrase is incorrect

JCESigner

public JCESigner(java.security.KeyStore ks,
                 PassPhraseAgent agent)
Creates a signer based on a fully loaded keystore

Parameters:
ks -
agent -
Method Detail

sign

public final byte[] sign(java.lang.String name,
                         byte[] data)
                  throws NonExistingSignerException,
                         UserCancellationException
Description copied from interface: Signer
Signs the data with the privatekey of the given name

Specified by:
sign in interface Signer
Parameters:
name - Alias of private key to be used within KeyStore
data - Data to be signed
Returns:
The signature
Throws:
NonExistingSignerException
UserCancellationException

sign

public final byte[] sign(java.lang.String name,
                         byte[] data,
                         boolean incorrect)
                  throws UserCancellationException,
                         NonExistingSignerException
Throws:
UserCancellationException
NonExistingSignerException

canSignFor

public final boolean canSignFor(java.lang.String name)
Description copied from interface: Signer
Returns true if the Signer contains a signer for the given name

Specified by:
canSignFor in interface Signer
Returns:
true if signer is contained

getKeyType

public final int getKeyType(java.lang.String name)
Description copied from interface: Signer
Checks the key type of the given alias

Specified by:
getKeyType in interface Signer
Returns:
KEY_NONE,KEY_RSA,KEY_DSA

generateKey

public final java.security.PublicKey generateKey(java.lang.String alias)
                                          throws UserCancellationException
Description copied from interface: Signer
Creates a new KeyPair, stores the PrivateKey using the given alias and returns the PublicKey.

Specified by:
generateKey in interface Signer
Returns:
Generated PublicKey
Throws:
UserCancellationException

generateKey

public java.security.PublicKey generateKey()
                                    throws UserCancellationException
Description copied from interface: Signer
Creates a new KeyPair, stores the PrivateKey using the base32 sha1 of the public key as it's alias and returns the PublicKey.

Specified by:
generateKey in interface Signer
Returns:
Generated PublicKey
Throws:
UserCancellationException

getPublicKey

public final java.security.PublicKey getPublicKey(java.lang.String name)
                                           throws NonExistingSignerException
Specified by:
getPublicKey in interface PublicKeySource
Throws:
NonExistingSignerException

sign

public byte[] sign(byte[] data,
                   SetPublicKeyCallBack callback)
            throws UserCancellationException
Specified by:
sign in interface BrowsableSigner
Throws:
UserCancellationException

sign

public byte[] sign(java.lang.String name,
                   char[] pass,
                   byte[] data,
                   SetPublicKeyCallBack callback)
            throws InvalidPassphraseException
Specified by:
sign in interface BrowsableSigner
Throws:
InvalidPassphraseException

createKeyPair

public void createKeyPair(java.lang.String alias,
                          char[] passphrase)
                   throws CryptoException
Specified by:
createKeyPair in interface BrowsableSigner
Throws:
CryptoException

save

public void save()
          throws UserCancellationException
Specified by:
save in interface Signer
Throws:
UserCancellationException

save

public final void save(java.lang.String filename)
                throws java.io.FileNotFoundException,
                       UserCancellationException
Throws:
java.io.FileNotFoundException
UserCancellationException

save

public final void save(java.lang.String filename,
                       char[] passphrase)
                throws java.io.FileNotFoundException
Throws:
java.io.FileNotFoundException

iterator

public java.util.Iterator iterator()
                            throws java.security.KeyStoreException
Specified by:
iterator in interface BrowsableSigner
Throws:
java.security.KeyStoreException


Copyright © 2003-2004 Antilles Software Ventures SA. All Rights Reserved.