iaik.security.rsa
Class RawRSASignature

java.lang.Object
  |
  +--java.security.SignatureSpi
        |
        +--java.security.Signature
              |
              +--iaik.security.rsa.RawRSASignature

public class RawRSASignature
extends Signature

This class represents a "raw" implemention of the RSA PKCS#1v1.5 digital signature algorithm (RSASSA-PKCS1-v1_5). Hashing and building a digest info object must be done by the application.

Digital signatures are used for ensuring data authentication and data integrity. RSA based signature algorithms use a proper hash function (like MD2, MD5 or SHA) for creating a message digest of the message to be signed. This class requires that the application does the hasing. Subsequently this message digest is encrypted with the RSA private key of the entity going to sign the message. Message and encrypted message digest together are sent to the intended receiver that verifies the signature by decrypting the received encrypted message digest with the corresponding RSA public key, and comparing it with the hash value derived from the received original message after hashing it with the same hash function as used by the entity that has sent the message.

This class follows the guidelines presented in PKCS#1) for implementing a signature algorithm based on the RSA encryption method.

An application wishing to sign some message or to verify some signature, generally has to perform four steps (in the following example, HASH has to be replaced by the name of the desired hash algorithm):

Version:
File Revision 8
See Also:
Signature

Field Summary
protected  ByteArrayOutputStream dataBuffer_
          Data buffer to which the DigestInfo is written when supplied via an update method.
 
Fields inherited from class java.security.Signature
SIGN, state, UNINITIALIZED, VERIFY
 
Fields inherited from class java.security.SignatureSpi
appRandom
 
Constructor Summary
RawRSASignature()
          Creates a RSA Signature object.
 
Method Summary
protected  Object engineGetParameter(String param)
          This method is not implemented and only throws an InvalidParameterException
protected  void engineInitSign(PrivateKey pk)
          SPI: Initializes this Signature object with the given RSA private key for going to sign some data.
protected  void engineInitVerify(PublicKey pk)
          SPI: Initializes this Signature object with the given RSA public key for performing a signature verification.
protected  void engineSetParameter(String param, Object value)
          This method is not implemented and only throws an InvalidParameterException
protected  byte[] engineSign()
          SPI: Returns a byte array holding the signature resulting from all already performed prepared hash update operations.
protected  void engineUpdate(byte b)
          SPI: Updates the data to be signed or verified with the specified byte.
protected  void engineUpdate(byte[] b, int off, int len)
          SPI: Updates the data to be signed or verified with the specified number of bytes, beginning at the specified offset within the given byte array.
protected  boolean engineVerify(byte[] sigBytes)
          Verifies the given signature of a message according to PKCS#1.
 
Methods inherited from class java.security.Signature
clone, getAlgorithm, getInstance, getInstance, getParameter, getProvider, initSign, initSign, initVerify, initVerify, setParameter, setParameter, sign, sign, toString, update, update, update, verify
 
Methods inherited from class java.security.SignatureSpi
engineInitSign, engineSetParameter, engineSign
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

dataBuffer_

protected ByteArrayOutputStream dataBuffer_
Data buffer to which the DigestInfo is written when supplied via an update method.
Constructor Detail

RawRSASignature

public RawRSASignature()
Creates a RSA Signature object.

Applications use

 Signature.getInstance("RSA");
 
for creating a Signature object.
See Also:
Signature.getInstance(java.lang.String)
Method Detail

engineInitVerify

protected void engineInitVerify(PublicKey pk)
                         throws InvalidKeyException
SPI: Initializes this Signature object with the given RSA public key for performing a signature verification.
Overrides:
engineInitVerify in class SignatureSpi
Parameters:
publicKey - the RSA public key belonging to the RSA private key that has been used for signing.
Throws:
InvalidKeyException - if a key encoding error occurs

engineInitSign

protected void engineInitSign(PrivateKey pk)
                       throws InvalidKeyException
SPI: Initializes this Signature object with the given RSA private key for going to sign some data.
Overrides:
engineInitSign in class SignatureSpi
Parameters:
privateKey - the RSA private key to be used for signing.
Throws:
InvalidKeyException - if a key encoding error occurs

engineSign

protected byte[] engineSign()
                     throws SignatureException
SPI: Returns a byte array holding the signature resulting from all already performed prepared hash update operations.
Overrides:
engineSign in class SignatureSpi
Returns:
a byte array holding the signature value
Throws:
SignatureException - if an error occurs when creating the signature

engineVerify

protected boolean engineVerify(byte[] sigBytes)
                        throws SignatureException
Verifies the given signature of a message according to PKCS#1.

PKCS#1 defines a signature as bit string, which has to be converted into an octet string, RSA decrypted with the signer´s RSA public key giving the prepared hash, which is normally an DER encoded DigestInfo object. This prepared hash is compared to the prepared hash provided by the applciation. If they are equal, the verification succeeded and true is returned, otherwise false is returned.

Please notice that first step of bit-string-to-octet-string conversion already has to be done when calling this verify method. In this way the supplied sigBytes value has to be the octet string signature value.

Overrides:
engineVerify in class SignatureSpi
Parameters:
sigBytes - the signature bytes to be verified
Returns:
true if signature is OK, false otherwise
Throws:
SignatureException - if an error occurs when verifying the signature

engineUpdate

protected void engineUpdate(byte b)
SPI: Updates the data to be signed or verified with the specified byte.
Overrides:
engineUpdate in class SignatureSpi
Parameters:
b - the byte to be used for updating.

engineUpdate

protected void engineUpdate(byte[] b,
                            int off,
                            int len)
SPI: Updates the data to be signed or verified with the specified number of bytes, beginning at the specified offset within the given byte array.
Overrides:
engineUpdate in class SignatureSpi
Parameters:
b - the byte array holding the data to be used for this update operation.
off - the offset, indicating the start position within the given byte array.
len - the number of bytes to be obtained from the given byte array, starting at the given position.

engineSetParameter

protected void engineSetParameter(String param,
                                  Object value)
                           throws InvalidParameterException
This method is not implemented and only throws an InvalidParameterException
Overrides:
engineSetParameter in class SignatureSpi
Throws:
InvalidParameterException - This Method is not supported

engineGetParameter

protected Object engineGetParameter(String param)
                             throws InvalidParameterException
This method is not implemented and only throws an InvalidParameterException
Overrides:
engineGetParameter in class SignatureSpi
Throws:
InvalidParameterException - This Method is not supported

This Javadoc may contain text parts from Internet Standard specifications (RFC 2459, 3280, 3039, 2560, 1521, 821, 822, 2253, 1319, 1321, ,2630, 2631, 2268, 3058, 2984, 2104, 2144, 2040, 2311, 2279, see copyright note) and RSA Data Security Public-Key Cryptography Standards (PKCS#1,3,5,7,8,9,10,12, see copyright note).

IAIK-JCE 3.1 with IAIK-JCE CC Core 3.1, (c) 1997-2004 IAIK