org.keyczar
Class Signer

java.lang.Object
  extended by org.keyczar.Verifier
      extended by org.keyczar.Signer

public class Signer
extends Verifier

Signers may both sign and verify data using sets of symmetric or private keys. Sets of public keys may only be used with Verifier objects. Signer objects should be used with symmetric or private key sets to generate signatures.

Author:
steveweis@gmail.com (Steve Weis)

Constructor Summary
Signer(KeyczarReader reader)
          Initialize a new Signer with a KeyczarReader.
Signer(java.lang.String fileLocation)
          Initialize a new Signer with a key set location.
 
Method Summary
 int digestSize()
          Returns the size of signatures produced by this Signer.
 byte[] sign(byte[] input)
          Sign the given input and return a signature.
 void sign(java.nio.ByteBuffer input, java.nio.ByteBuffer output)
          Sign the given input and write the signature to the given ByteBuffer
 java.lang.String sign(java.lang.String input)
          Signs the given input String and return the output as a web-safe Base64 encoded String.
 java.lang.String toString()
           
 
Methods inherited from class org.keyczar.Verifier
verify, verify, verify
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Signer

public Signer(KeyczarReader reader)
       throws KeyczarException
Initialize a new Signer with a KeyczarReader. The corresponding key set must have a purpose KeyPurpose.SIGN_AND_VERIFY.

Parameters:
reader - A reader to read keys from
Throws:
KeyczarException - In the event of an IO error reading keys or if the key set does not have the appropriate purpose.

Signer

public Signer(java.lang.String fileLocation)
       throws KeyczarException
Initialize a new Signer with a key set location. This will attempt to read the keys using a KeyczarFileReader. The corresponding key set must have a purpose of KeyPurpose.SIGN_AND_VERIFY.

Parameters:
fileLocation - Directory containing a key set
Throws:
KeyczarException - In the event of an IO error reading keys or if the key set does not have the appropriate purpose.
Method Detail

digestSize

public int digestSize()
               throws KeyczarException
Returns the size of signatures produced by this Signer.

Returns:
The size of signatures produced by this Signer.
Throws:
KeyczarException - If this Signer does not have a primary or a JCE exception occurs.

sign

public byte[] sign(byte[] input)
            throws KeyczarException
Sign the given input and return a signature.

Parameters:
input - The input to sign.
Returns:
A byte array representation of a signature.
Throws:
KeyczarException - If this Signer does not have a primary or a JCE exception occurs.

sign

public void sign(java.nio.ByteBuffer input,
                 java.nio.ByteBuffer output)
          throws KeyczarException
Sign the given input and write the signature to the given ByteBuffer

Parameters:
input - The input to sign.
output - The ByteBuffer to write the signature in.
Throws:
KeyczarException - If this Signer does not have a primary or a JCE exception occurs.

sign

public java.lang.String sign(java.lang.String input)
                      throws KeyczarException
Signs the given input String and return the output as a web-safe Base64 encoded String.

Parameters:
input - The input String to sign.
Returns:
A web-safe Base64-encoded representation of a signature on the input.
Throws:
KeyczarException

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object