FileDocCategorySizeDatePackage
Signature.javaAPI DocphoneME MR2 API (J2ME)7174Wed May 02 18:00:38 BST 2007java.security

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.
version
1.91, 01/23/03

Fields Summary
com.sun.midp.crypto.Signature
sign
Signature implementation.
Constructors Summary
Signature(String algorithm)
Creates a Signature object for the specified algorithm.

param
algorithm the standard string name of the algorithm. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.

    
Methods Summary
public static java.security.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.

        try {
            return new SignatureImpl(algorithm,
                com.sun.midp.crypto.Signature.getInstance(algorithm));
        } catch (com.sun.midp.crypto.NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(e.getMessage());
        }
    
public final voidinitVerify(java.security.PublicKey publicKey)
Initializes this object for verification. If this method is called again with a different argument, it negates the effect of this call.

param
publicKey the public key of the identity whose signature is going to be verified.
exception
InvalidKeyException if the key is invalid.

        if (! (publicKey instanceof RSAPublicKey)) {
            throw new InvalidKeyException();
        }

        try {
            sign.initVerify(((RSAPublicKey)publicKey).getKey());
        } catch (com.sun.midp.crypto.InvalidKeyException e) {
            throw new InvalidKeyException(e.getMessage());
        }
    
public final voidupdate(byte[] data, int off, int len)
Updates the data to be verified, using the specified array of bytes, starting at the specified offset.

param
data the array of bytes.
param
off the offset to start from in the array of bytes.
param
len the number of bytes to use, starting at offset.
exception
SignatureException if this signature object is not initialized properly.

        try {
            sign.update(data, off, len);
        } catch (com.sun.midp.crypto.SignatureException e) {
            throw new SignatureException(e.getMessage());
        }
    
public final 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.

        try {
            return sign.verify(signature);
        } catch (com.sun.midp.crypto.SignatureException e) {
            throw new SignatureException(e.getMessage());
        }