com.motorola.iden.security
Class Signature

java.lang.Object
  |
  +--com.motorola.iden.security.Signature

public class Signature
extends java.lang.Object

This Signature class is used to provide applications the functionality of a digital signature algorithm. Digital signatures are used for authentication and integrity assurance of digital data.

The signature algorithm can be, among others, ECDSA, using ECDSA and SHA-1. The DSA algorithm using the SHA-1 message digest algorithm can be specified as ECDSA. In the case of RSA, there are multiple choices for the message digest algorithm, so the signing algorithm could be specified as, for example, MD5withRSA, or SHA1withRSA. The algorithm name must be specified, as there is no default.

MOTOROLA and the Stylized M Logo are registered trademarks of Motorola, Inc. Reg. U.S. Pat. & Tm. Off.
© Copyright 2002 - 2004 Motorola, Inc. All Rights Reserved.


Field Summary
protected static int SIGN
          Possible state value, signifying that this signature has been initialized for signing.
protected  int state
          Current state of this signature object.
protected static int UNINITIALIZED
          Possible state value, signifying that this signature has not yet been initialized.
protected static int VERIFY
          Possible state value, signifying that this signature has been initialized for verifying.
 
Constructor Summary
protected Signature(SignatureSpi signaturespi)
          Creates a Signature object.
 
Method Summary
static Signature getInstance(java.lang.String algorithm)
          Generates a Signature object that implements the signature algorithm.
 AlgorithmParameterSpec getParameter()
          The returned parameters may be the same that were used to initialize this signature engine, or may contain a combination of default and randomly generated parameter values used by the underlying signature implementation if this signature engine requires algorithm parameters but was not initialized with any.
 void initSign(PrivateKey privateKey)
          Initialize this object for signing.
 void initVerify(PublicKey publicKey)
          Initializes this object for verification.
 void setParameter(AlgorithmParameterSpec params)
          Setup the parameters for signing or verifying.
 byte[] sign()
          Returns the signature bytes of the input data.
 void update(byte[] data, int offset, int len)
          Updates the data to be signed or verified, using the specified array of bytes, starting at the specified offset.
 boolean verify(byte[] signature)
          Verifies the passed-in signature in the specified array of bytes, starting at the specified offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

UNINITIALIZED

protected static final int UNINITIALIZED
Possible state value, signifying that this signature has not yet been initialized.


SIGN

protected static final int SIGN
Possible state value, signifying that this signature has been initialized for signing.


VERIFY

protected static final int VERIFY
Possible state value, signifying that this signature has been initialized for verifying.


state

protected int state
Current state of this signature object.

Constructor Detail

Signature

protected Signature(SignatureSpi signaturespi)
Creates a Signature object.

Parameters:
signaturespi - the instance of an algorithm which implements SignatureSpi
Method Detail

getInstance

public static Signature getInstance(java.lang.String algorithm)
                             throws NoSuchAlgorithmException
Generates a Signature object that implements the signature algorithm.

Parameters:
algorithm - name of the algorithm. ECDSA, MD5withRSA and SHA1withRSA are available in current implementation.
Returns:
a signature object that implements the requested algorithm. NoSuchAlgorithmException if the specified algorithm is not available.

initSign

public final void initSign(PrivateKey privateKey)
                    throws InvalidKeyException
Initialize this object for signing. If this method is called again with a different argument, it negates the effect of this call.

Parameters:
privateKey - the private key of the identity whose signature is going to be generated.

Throws:
InvalidKeyException - if the key is invalid.

initVerify

public final void initVerify(PublicKey publicKey)
                      throws InvalidKeyException
Initializes this object for verification. If this method is called again with a different argument, it negates the effect of this call.

Parameters:
publicKey - the public key of the identity whose signature is going to be verified.

Throws:
InvalidKeyException - if the key is invalid.

update

public final void update(byte[] data,
                         int offset,
                         int len)
                  throws SignatureException
Updates the data to be signed or verified, using the specified array of bytes, starting at the specified offset.
Parameters:
data - the array of bytes.
offset - the offset to start from in the array of bytes.
len - the number of bytes to use, starting at offset.
Throws:
SignatureException - if this signature object is not initialized properly.

sign

public final byte[] sign()
                  throws SignatureException
Returns the signature bytes of the input data. The format of the signature depends on the underlying signature scheme. A call to this method resets this signature object to the state it was in when previously initialized for signing via a call to initSign(PrivateKey).

Returns:
the signature bytes of the signing operation's result.

Throws:
SignatureException - if this signature object is not initialized properly or input is null.

verify

public final boolean verify(byte[] signature)
                     throws SignatureException
Verifies the passed-in signature in the specified array of bytes, starting at the specified offset.

A call to this method resets this signature object to the state it was in when previously initialized for verification via a call to initVerify(PublicKey).

Parameters:
signature - the signature bytes to be verified.

Returns:
true if the signature was verified, false if not.

Throws:
SignatureException - if this signature object is not initialized properly or the input signature is null.

setParameter

public void setParameter(AlgorithmParameterSpec params)
                  throws InvalidAlgorithmParameterException
Setup the parameters for signing or verifying.

Parameters:
params - the parameters

Throws:
InvalidAlgorithmParameterException - if this method is overridden by a provider and the the given parameters are inappropriate for this signature engine

getParameter

public AlgorithmParameterSpec getParameter()

The returned parameters may be the same that were used to initialize this signature engine, or may contain a combination of default and randomly generated parameter values used by the underlying signature implementation if this signature engine requires algorithm parameters but was not initialized with any.

Returns:
the parameters used with this signature engine, or null if this signature engine does not use any parameters