ewe.security
Class Signature

java.lang.Object
  extended byewe.security.Signature

public class Signature
extends Object

A Signature is used to either hold a received Ewe digital signature, or to generate a Ewe digital signature.


Field Summary
 int length
          This is the length of the document being signed.
 byte[] signature
          This is the fully encoded signature bytes for transmission or storage along with the document.
 EncryptionKey signersKey
          This is the signer's public key (for verifying signatures) or private key (for creating signatures).
 Time time
          This is an optional timestamp to be embedded in the signature.
 
Constructor Summary
Signature(byte[] signature, EncryptionKey signersPublicKey)
          This is used on a signature that has already been generated.
Signature(EncryptionKey signersPrivateKey, Time signatureTime)
          Create a Signature object in preparation for signing.
 
Method Summary
 byte[] sign(byte[] data, int offset, int length, SHA1 digest)
          Produce a signature for a document.
 boolean verify(byte[] data, int offset, int length, SHA1 digest)
          Verify that a document is the same as the one that was signed with this signature.
 boolean verify(int dataLength, byte[] digest)
          Verify that a document with a particular data length and with a particular digest bytes is the same as the one that was signed with this signature.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, toString
 

Field Detail

signersKey

public EncryptionKey signersKey
This is the signer's public key (for verifying signatures) or private key (for creating signatures).


time

public Time time
This is an optional timestamp to be embedded in the signature.


length

public int length
This is the length of the document being signed.


signature

public byte[] signature
This is the fully encoded signature bytes for transmission or storage along with the document.

Constructor Detail

Signature

public Signature(byte[] signature,
                 EncryptionKey signersPublicKey)
          throws StreamCorruptedException
This is used on a signature that has already been generated. After the construction, the length variable will hold the length of the document and the time variable will be set to the timestamp in the signature, or null if no timestamp was encoded.

After calling this constructor you can call the verify() methods to verify if a document is the one that was signed.

Parameters:
signature - the recieved or stored encoded signature bytes.
signersPublicKey - the public key of the signer.
Throws:
StreamCorruptedException - if the data is invalid in any way.

Signature

public Signature(EncryptionKey signersPrivateKey,
                 Time signatureTime)
Create a Signature object in preparation for signing. After creating the object with this constructor, you should call one of the sign() methods.

Parameters:
signatureTime - an optional timestamp to include in the signature.
Method Detail

sign

public byte[] sign(byte[] data,
                   int offset,
                   int length,
                   SHA1 digest)
            throws IOException
Produce a signature for a document. The signature variable is set to be the final signature bytes and this is also returned.

Parameters:
data - the data bytes to sign.
offset - the start of the data bytes in the data parameter.
length - the number of bytes in the data.
digest - an optional pre-created SHA1 object to create the document digest.
Returns:
the bytes for the signature.
Throws:
IOException - if an encryption of data processing error occurs.

verify

public boolean verify(int dataLength,
                      byte[] digest)
Verify that a document with a particular data length and with a particular digest bytes is the same as the one that was signed with this signature.

Parameters:
dataLength - the length of the data.
digest - the SHA1 digest of the data.
Returns:
true if it verified correctly.

verify

public boolean verify(byte[] data,
                      int offset,
                      int length,
                      SHA1 digest)
Verify that a document is the same as the one that was signed with this signature.

Parameters:
data - the data to verify.
offset - the start of the data.
length - the number of bytes in the data.
digest - an optional pre-created SHA1 object to digest the data.
Returns:
true if it verified correctly.