FileDocCategorySizeDatePackage
Signature.javaAPI DocphoneME MR2 API (J2ME)9641Wed May 02 18:00:24 BST 2007com.sun.midp.crypto

Signature

public abstract class Signature extends Object
This Signature class is used to provide applications the functionality of a digital signature algorithm. Digital signatures are used for authentication and integrity assurance of digital data.

The signature algorithm can be, among others, the NIST standard DSA, using DSA and SHA-1. The DSA algorithm using the SHA-1 message digest algorithm can be specified as SHA1withDSA. In the case of RSA, there are multiple choices for the message digest algorithm, so the signing algorithm could be specified as, for example, MD2withRSA, MD5withRSA, or SHA1withRSA. The algorithm name must be specified, as there is no default. When an algorithm name is specified, the system will determine if there is an implementation of the algorithm requested available in the environment, and if there is more than one, if there is a preferred one.

A Signature object can be used to generate and verify digital signatures.

There are three phases to the use of a Signature object for verifying a signature:

  1. Initialization, with a public key, which initializes the signature for verification
  2. Updating

    Depending on the type of initialization, this will update the bytes to be verified.

  3. Verifying a signature on all updated bytes.

Fields Summary
Constructors Summary
protected Signature()
Protected constructor.

    
Methods Summary
public abstract java.lang.StringgetAlgorithm()
Gets the signature algorithm.

return
the algorithm code defined above

public static com.sun.midp.crypto.SignaturegetInstance(java.lang.String algorithm)
Generates a Signature object that implements the specified digest algorithm.

param
algorithm the standard name of the algorithm requested. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
return
the new Signature object.
exception
NoSuchAlgorithmException if the algorithm is not available in the environment.


        if (algorithm == null) {
            throw new NoSuchAlgorithmException();
        }

        algorithm = algorithm.toUpperCase();

        try {
            Class sigClass;

            if (algorithm.equals("MD5WITHRSA")) {
                sigClass = Class.forName("com.sun.midp.crypto.RsaMd5Sig");
            } else if (algorithm.equals("SHA1WITHRSA")) {
                sigClass = Class.forName("com.sun.midp.crypto.RsaShaSig");
            } else {
                throw new NoSuchAlgorithmException();
            }
                
            return (Signature)sigClass.newInstance();
        } catch (Throwable e) {
            throw new NoSuchAlgorithmException("Provider not found");
        }
    
public abstract intgetLength()
Gets the byte length of the signature data.

return
the byte length of signature data

public abstract voidinitSign(PrivateKey theKey)
Initializes the Signature object with the appropriate Key for signature creation.

param
theKey the key object to use for signing
exception
InvalidKeyException if the key type is inconsistent with the mode or signature implementation.

public abstract voidinitVerify(PublicKey theKey)
Initializes the Signature object with the appropriate Key for signature verification.

param
theKey the key object to use for verification
exception
InvalidKeyException if the key type is inconsistent with the mode or signature implementation.

public intsign(byte[] outbuf)
Generates the signature of all/last input data. A call to this method also resets this signature object to the state it was in when previously initialized via a call to initSign() and the message to sign given via a call to update(). That is, the object is reset and available to sign another message.

param
outbuf the output buffer to store signature data
return
number of bytes of signature output in sigBuf
exception
SignatureException if this signature object is not initialized properly, or outbuf.length is less than the actual signature

        return sign(outbuf, 0, outbuf.length);
    
public abstract intsign(byte[] outbuf, int offset, int len)
Generates the signature of all/last input data. A call to this method also resets this signature object to the state it was in when previously initialized via a call to initSign() and the message to sign given via a call to update(). That is, the object is reset and available to sign another message.

param
outbuf the output buffer to store signature data
param
offset starting offset within the output buffer at which to begin signature data
param
len max byte to write to the buffer
return
number of bytes of signature output in sigBuf
exception
SignatureException if this signature object is not initialized properly, or len is less than the actual signature

public abstract voidupdate(byte[] inBuf, int inOff, int inLen)
Accumulates a signature of the input data. When this method is used, temporary storage of intermediate results is required. This method should only be used if all the input data required for the signature is not available in one byte array. The sign() or verify() method is recommended whenever possible.

param
inBuf the input buffer of data to be signed
param
inOff starting offset within the input buffer for data to be signed
param
inLen the byte length of data to be signed
exception
SignatureException if this signature object is not initialized properly.

public booleanverify(byte[] signature)
Verifies the passed-in signature.

A call to this method resets this signature object to the state it was in when previously initialized for verification via a call to initVerify(PublicKey). That is, the object is reset and available to verify another signature from the identity whose public key was specified in the call to initVerify.

param
signature the signature bytes to be verified.
return
true if the signature was verified, false if not.
exception
SignatureException if this signature object is not initialized properly, or the passed-in signature is improperly encoded or of the wrong type, etc.

        return verify(signature, 0, signature.length);
    
public abstract booleanverify(byte[] signature, int offset, int length)
Verifies the passed-in signature.

A call to this method resets this signature object to the state it was in when previously initialized for verification via a call to initVerify(PublicKey). That is, the object is reset and available to verify another signature from the identity whose public key was specified in the call to initVerify.

param
signature the input buffer containing signature data
param
offset starting offset within the sigBuf where signature data begins
param
length byte length of signature data
return
true if signature verifies, false otherwise
exception
SignatureException if this signature object is not initialized properly, or the passed-in signature is improperly encoded or of the wrong type, etc.