org.neuclear.commons.crypto.signers
Class SimpleSigner

java.lang.Object
  extended by org.neuclear.commons.crypto.signers.SimpleSigner
All Implemented Interfaces:
Signer

public final class SimpleSigner
extends java.lang.Object
implements Signer

Simple memory based implementation of Signer. Currently it doesnt even use the passphrase. However it does do a SHA1 digest on the name first.


Field Summary
 
Fields inherited from interface org.neuclear.commons.crypto.signers.Signer
KEY_DSA, KEY_NONE, KEY_OTHER, KEY_RSA
 
Constructor Summary
SimpleSigner(java.lang.String file, PassPhraseAgent agent)
           
 
Method Summary
 void addKey(java.lang.String name, char[] passphrase, java.security.PrivateKey key)
          Adds the given key to the store.
 void addKey(java.lang.String name, java.security.PrivateKey key)
          Adds the given key to the store.
 boolean canSignFor(java.lang.String name)
          Returns true if the Signer contains a signer for the given name
 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.
protected static java.lang.String getDigestedName(java.lang.String name)
           
 int getKeyType(java.lang.String name)
          Checks the key type of the given alias
 void save()
           
 byte[] sign(java.lang.String name, byte[] data)
          Signs the data with the privatekey of the given name
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SimpleSigner

public SimpleSigner(java.lang.String file,
                    PassPhraseAgent agent)
Method Detail

addKey

public final void addKey(java.lang.String name,
                         java.security.PrivateKey key)
                  throws UserCancellationException
Adds the given key to the store. Uses the PassPhrase agent to ask for PassPhrase.

Parameters:
name - The name to store it as
key - The PrivateKey itself.
Throws:
UserCancellationException

addKey

public final void addKey(java.lang.String name,
                         char[] passphrase,
                         java.security.PrivateKey key)
Adds the given key to the store.

Parameters:
name - The name to store it as
passphrase - The passphrase to encrypt the key
key - The PrivateKey itself.

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)
Checks the key type of the given alias

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

getDigestedName

protected static final java.lang.String getDigestedName(java.lang.String name)

save

public final void save()
Specified by:
save in interface Signer

sign

public final byte[] sign(java.lang.String name,
                         byte[] data)
                  throws UserCancellationException
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:
UserCancellationException

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


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