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

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
com.sun.midp.crypto.MessageDigest
messageDigest
Message digest implementation.
Constructors Summary
MessageDigest(String algorithm)
Creates a message digest with the specified algorithm name.

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

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

        try {
            return messageDigest.digest(buf, offset, len);
        } catch (com.sun.midp.crypto.DigestException e) {
            throw new DigestException(e.getMessage());
        }
    
public static java.security.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.


        try {
            return new MessageDigestImpl(algorithm,
                com.sun.midp.crypto.MessageDigest.getInstance(algorithm));
        } catch (com.sun.midp.crypto.NoSuchAlgorithmException e) {
            throw new NoSuchAlgorithmException(e.getMessage());
        }
    
public voidreset()
Resets the digest for further use.

        messageDigest.reset();
    
public voidupdate(byte[] input, int offset, int len)
Updates the digest using the specified array of bytes, starting at the specified offset.

param
input the array of bytes.
param
offset the offset to start from in the array of bytes.
param
len the number of bytes to use, starting at offset.

        messageDigest.update(input, offset, len);