Use is subject to License Terms. Your use of this web site or any of its contents or software indicates your agreement to be bound by these License Terms.

Copyright © 2006 Sun Microsystems, Inc. All rights reserved.

JSR 177

java.security
Class MessageDigest

java.lang.Object
  extended by java.security.MessageDigest

public abstract class MessageDigest
extends java.lang.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 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.


Method Summary
 int digest(byte[] buf, int offset, int len)
          Completes the hash computation by performing final operations such as padding.
static MessageDigest getInstance(java.lang.String algorithm)
          Generates a MessageDigest object that implements the specified digest algorithm.
 void reset()
          Resets the digest for further use.
 void update(byte[] input, int offset, int len)
          Updates the digest using the specified array of bytes, starting at the specified offset.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getInstance

public static MessageDigest getInstance(java.lang.String algorithm)
                                 throws NoSuchAlgorithmException
Generates a MessageDigest object that implements the specified digest algorithm.

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

update

public void update(byte[] input,
                   int offset,
                   int len)
Updates the digest using the specified array of bytes, starting at the specified offset.

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

digest

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

Parameters:
buf - output buffer for the computed digest
offset - offset into the output buffer to begin storing the digest
len - number of bytes within buf allotted for the digest
Returns:
the number of bytes placed into buf
Throws:
DigestException - if an error occurs.

reset

public void reset()
Resets the digest for further use.


JSR 177

Copyright © 2006 Sun Microsystems, Inc. All rights reserved. Use is subject to License Terms. Your use of this web site or any of its content or software indicates your agreement to be bound by these License Terms.

For more information, please consult the JSR 177 specification.