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

MessageDigest

public abstract class MessageDigest extends Object
This MessageDigest class provides applications the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A MessageDigest object starts out initialized. The data is processed through it using the update method. At any point {@link #reset() reset} can be called to reset the digest. Once all the data to be updated has been updated, the digest method should be called to complete the hash computation.

The digest method can be called once for a given number of updates. After digest has been called, the MessageDigest object is reset to its initialized state.

Fields Summary
Constructors Summary
protected MessageDigest()
Protected constructor.

    
Methods Summary
public abstract java.lang.Objectclone()
Clones the MessageDigest object.

return
a clone of this object

public abstract intdigest(byte[] buf, int offset, int len)
Completes the hash computation by performing final operations such as padding. The digest is reset after this call is made.

param
buf output buffer for the computed digest
param
offset offset into the output buffer to begin storing the digest
param
len number of bytes within buf allotted for the digest
return
the number of bytes placed into buf
exception
DigestException if an error occurs.

public abstract java.lang.StringgetAlgorithm()
Gets the message digest algorithm.

return
algorithm implemented by this MessageDigest object

public abstract intgetDigestLength()
Gets the length (in bytes) of the hash.

return
byte-length of the hash produced by this object

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

param
algorithm the name of the algorithm requested. See Appendix A in the Java Cryptography Architecture API Specification & Reference for information about standard algorithm names.
return
a MessageDigest object implementing the specified algorithm.
exception
NoSuchAlgorithmException if the algorithm is not available in the caller's environment.


        if (algorithm == null || algorithm.length() == 0) {
            throw new IllegalArgumentException();
        }

        algorithm = algorithm.toUpperCase();

        if (algorithm.equals("MD2")) {
            return new MD2();
        } else if (algorithm.equals("MD5")) {
            return new MD5();
        } else if (algorithm.equals("SHA-1")) {
            return new SHA();
        }

        throw new NoSuchAlgorithmException(algorithm);
    
public abstract voidreset()
Resets the MessageDigest to the initial state for further use.

public abstract voidupdate(byte[] inBuf, int inOff, int inLen)
Accumulates a hash of the input data. This method is useful when the input data to be hashed is not available in one byte array.

param
inBuf input buffer of data to be hashed
param
inOff offset within inBuf where input data begins
param
inLen length (in bytes) of data to be hashed
see
#doFinal(byte[], int, int, byte[], int)