edu.vt.middleware.crypt.signature
Class SignatureAlgorithm

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractAlgorithm
      extended by edu.vt.middleware.crypt.signature.SignatureAlgorithm
All Implemented Interfaces:
Algorithm
Direct Known Subclasses:
AbstractDSASignature, RSASignature

public class SignatureAlgorithm
extends AbstractAlgorithm

SignatureAlgorithm provides message signing and verification operations.

Version:
$Revision: 2744 $
Author:
Middleware Services

Field Summary
protected  DigestAlgorithm digest
          Message digest used to compute encoded message for signing.
protected  PrivateKey signKey
          Private key used for signing.
protected  PublicKey verifyKey
          Public key used for verification.
 
Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
algorithm, logger, randomByteSize, randomProvider
 
Constructor Summary
protected SignatureAlgorithm(String alg)
          Creates a new instance of a the given signature algorithm.
 
Method Summary
 Object clone()
          
 void initSign()
          Initialize the signature for the sign(byte[]) operation.
 void initVerify()
          Initialize the signature for the verify(byte[], byte[]) operation.
static SignatureAlgorithm newInstance(String algorithm)
          Creates a new instance that uses the given signature algorithm to compute and verify signatures.
static SignatureAlgorithm newInstance(String algorithm, String digestAlgorithm)
          Creates a new instance that uses the given signature algorithm and digest algorithm to compute and verify signatures.
 void setSignKey(PrivateKey key)
          Sets the private key used for signing.
 void setVerifyKey(PublicKey key)
          Sets the public key used for verification.
 byte[] sign(byte[] data)
          Signs the given data and returns the signature as a byte array.
 String sign(byte[] data, Converter converter)
          Signs the given data and returns the signature as a string using the conversion strategy provided by the given converter.
 byte[] sign(InputStream in)
          Computes the signature of the data in the given input stream by processing in chunks.
 String sign(InputStream in, Converter converter)
          Computes the signature of the data in the given input stream by processing in chunks.
 boolean verify(byte[] data, byte[] signature)
          Verifies the signature of the given data matches the given signature.
 boolean verify(byte[] data, String signature, Converter converter)
          Verifies the signature of the given data matches the given signature.
 boolean verify(InputStream in, byte[] signature)
          Verifies the signature of the given data matches the given signature.
 boolean verify(InputStream in, String signature, Converter converter)
          Verifies the signature of the data in the given input stream matches the given signature.
 
Methods inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
getAlgorithm, getRandomData, setRandomProvider, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

signKey

protected PrivateKey signKey
Private key used for signing.


verifyKey

protected PublicKey verifyKey
Public key used for verification.


digest

protected DigestAlgorithm digest
Message digest used to compute encoded message for signing.

Constructor Detail

SignatureAlgorithm

protected SignatureAlgorithm(String alg)
Creates a new instance of a the given signature algorithm.

Parameters:
alg - Signature algorithm name, e.g. DSA, RSA.
Method Detail

newInstance

public static SignatureAlgorithm newInstance(String algorithm)
Creates a new instance that uses the given signature algorithm to compute and verify signatures.

Parameters:
algorithm - Signature algorithm name.
Returns:
New instance of signature algorithm.

newInstance

public static SignatureAlgorithm newInstance(String algorithm,
                                             String digestAlgorithm)
Creates a new instance that uses the given signature algorithm and digest algorithm to compute and verify signatures.

Parameters:
algorithm - Signature algorithm name.
digestAlgorithm - Message digest algorithm name.
Returns:
New instance of signature algorithm.

setSignKey

public void setSignKey(PrivateKey key)
Sets the private key used for signing.

Parameters:
key - Private key.

setVerifyKey

public void setVerifyKey(PublicKey key)
Sets the public key used for verification.

Parameters:
key - Public key.

initSign

public void initSign()
              throws CryptException
Initialize the signature for the sign(byte[]) operation.

Throws:
CryptException - On signature initialization failure.

initVerify

public void initVerify()
                throws CryptException
Initialize the signature for the verify(byte[], byte[]) operation.

Throws:
CryptException - On verification initialization failure.

sign

public byte[] sign(byte[] data)
            throws CryptException
Signs the given data and returns the signature as a byte array.

Parameters:
data - Data to be signed.
Returns:
Signature of given data as byte array.
Throws:
CryptException - On signature failure.

sign

public String sign(byte[] data,
                   Converter converter)
            throws CryptException
Signs the given data and returns the signature as a string using the conversion strategy provided by the given converter.

Parameters:
data - Data to be signed.
converter - Converts raw signature bytes to a string.
Returns:
Signature of given data as a string.
Throws:
CryptException - On signature failure.

sign

public byte[] sign(InputStream in)
            throws CryptException,
                   IOException
Computes the signature of the data in the given input stream by processing in chunks.

Parameters:
in - Input stream containing data to be signed.
Returns:
Signature of given data as byte array.
Throws:
CryptException - On signature failure.
IOException - On input stream read errors.

sign

public String sign(InputStream in,
                   Converter converter)
            throws CryptException,
                   IOException
Computes the signature of the data in the given input stream by processing in chunks.

Parameters:
in - Input stream containing data to be signed.
converter - Converts raw signature bytes to a string.
Returns:
Signature of given data as a string.
Throws:
CryptException - On signature failure.
IOException - On input stream read errors.

verify

public boolean verify(byte[] data,
                      byte[] signature)
               throws CryptException
Verifies the signature of the given data matches the given signature.

Parameters:
data - Data to be verified.
signature - Signature to be used for comparison.
Returns:
True if the signed data matches the given signature, false otherwise.
Throws:
CryptException - On verification failure.

verify

public boolean verify(byte[] data,
                      String signature,
                      Converter converter)
               throws CryptException
Verifies the signature of the given data matches the given signature.

Parameters:
data - Data to be verified.
signature - String representation of signature to be used for comparison.
converter - Converts the signature string representation into raw bytes required for verification.
Returns:
True if the signed data matches the given signature, false otherwise.
Throws:
CryptException - On verification failure.

verify

public boolean verify(InputStream in,
                      byte[] signature)
               throws CryptException,
                      IOException
Verifies the signature of the given data matches the given signature.

Parameters:
in - Input stream containing data to be verified.
signature - Signature to be used for comparison.
Returns:
True if the signed data matches the given signature, false otherwise.
Throws:
CryptException - On verification failure.
IOException - On input stream read errors.

verify

public boolean verify(InputStream in,
                      String signature,
                      Converter converter)
               throws CryptException,
                      IOException
Verifies the signature of the data in the given input stream matches the given signature.

Parameters:
in - Input stream containing data to be verified.
signature - String representation of signature to be used for comparison.
converter - Converts the signature string representation into raw bytes required for verification.
Returns:
True if the signed data matches the given signature, false otherwise.
Throws:
CryptException - On verification failure.
IOException - On input stream read errors.

clone

public Object clone()
             throws CloneNotSupportedException

Overrides:
clone in class Object
Throws:
CloneNotSupportedException


Copyright © 2003-2013 Virginia Tech. All Rights Reserved.