edu.vt.middleware.crypt.signature
Class RSASignature

java.lang.Object
  extended by edu.vt.middleware.crypt.AbstractAlgorithm
      extended by edu.vt.middleware.crypt.signature.SignatureAlgorithm
          extended by edu.vt.middleware.crypt.signature.RSASignature
All Implemented Interfaces:
Algorithm

public class RSASignature
extends SignatureAlgorithm

Implements the RSASSA-PKCS1-v1_5 signature algorithm described in http://www.ietf.org/rfc/rfc2437.txt.

Version:
$Revision: 2745 $
Author:
Middleware Services

Field Summary
 
Fields inherited from class edu.vt.middleware.crypt.signature.SignatureAlgorithm
digest, signKey, verifyKey
 
Fields inherited from class edu.vt.middleware.crypt.AbstractAlgorithm
algorithm, logger, randomByteSize, randomProvider
 
Constructor Summary
RSASignature()
          Creates a new RSA signature class that uses a SHA-1 for message digest computation.
RSASignature(DigestAlgorithm d)
          Creates a new RSA signature class that uses the given digest algorithm for message digest computation.
 
Method Summary
protected  void chunkUpdate(InputStream in)
          Update the signer in chunks with data read from the input stream.
protected  void init(boolean forSigning, org.bouncycastle.crypto.CipherParameters params)
          Initialize the signer.
 void initSign()
          Initialize the signature for the SignatureAlgorithm.sign(byte[]) operation.
 void initVerify()
          Initialize the signature for the SignatureAlgorithm.verify(byte[], byte[]) operation.
 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.
 byte[] sign(InputStream in)
          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(InputStream in, byte[] signature)
          Verifies the signature of the given data matches the given signature.
 
Methods inherited from class edu.vt.middleware.crypt.signature.SignatureAlgorithm
clone, newInstance, newInstance, sign, sign, verify, verify
 
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
 

Constructor Detail

RSASignature

public RSASignature()
Creates a new RSA signature class that uses a SHA-1 for message digest computation.


RSASignature

public RSASignature(DigestAlgorithm d)
Creates a new RSA signature class that uses the given digest algorithm for message digest computation.

Parameters:
d - Message digest algorithm.
Method Detail

setSignKey

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

Overrides:
setSignKey in class SignatureAlgorithm
Parameters:
key - Private key.

setVerifyKey

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

Overrides:
setVerifyKey in class SignatureAlgorithm
Parameters:
key - Public key.

initSign

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

Overrides:
initSign in class SignatureAlgorithm

initVerify

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

Overrides:
initVerify in class SignatureAlgorithm

sign

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

Overrides:
sign in class SignatureAlgorithm
Parameters:
data - Data to be signed.
Returns:
Signature of given data as byte array.
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.

Overrides:
sign in class SignatureAlgorithm
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.

verify

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

Overrides:
verify in class SignatureAlgorithm
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(InputStream in,
                      byte[] signature)
               throws CryptException,
                      IOException
Verifies the signature of the given data matches the given signature.

Overrides:
verify in class SignatureAlgorithm
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.

init

protected void init(boolean forSigning,
                    org.bouncycastle.crypto.CipherParameters params)
Initialize the signer.

Parameters:
forSigning - Whether to initialize signer for the sign operation.
params - BC cipher parameters.

chunkUpdate

protected void chunkUpdate(InputStream in)
                    throws IOException
Update the signer in chunks with data read from the input stream.

Parameters:
in - Input stream to read from.
Throws:
IOException - On IO errors.


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