<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<!--NewPage-->
<html>
<head>
<!-- Generated by javadoc on Wed Jul 28 01:21:15 GMT 1999 -->
<title>
  Class java.security.MessageDigest
</title>
</head>
<body>
<a name="_top_"></a>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.security.html">This Package</a>  <a href="java.security.KeyPairGenerator.html#_top_">Previous</a>  <a href="java.security.Provider.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
<hr>
<h1>
  Class java.security.MessageDigest
</h1>
<pre>
<a href="java.lang.Object.html#_top_">java.lang.Object</a>
   |
   +----java.security.MessageDigest
</pre>
<hr>
<dl>
  <dt> public abstract class <b>MessageDigest</b>
  <dt> extends <a href="java.lang.Object.html#_top_">Object</a>
</dl>
This MessageDigest class provides 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.
 <p>Like other algorithm-based classes in Java Security, 
 MessageDigest has two major components:
 <dl>
 <dt><b>Message Digest API</b> (Application Program Interface)
 <dd>This is the interface of methods called by applications needing 
 message digest services. The API consists of all public methods.
 <dt><b>Message Digest SPI</b> (Service Provider Interface)
 <dd>This is the interface implemented by providers that supply
 specific algorithms. It consists of all methods whose names
 are prefixed by <em>engine</em>. Each such method is called by    
 a correspondingly-named public API method. For example,
 the <code>engineReset</code> method is    
 called by the <code>reset</code> method.    
 The SPI methods are abstract; providers must supply a    
 concrete implementation.
 </dl>
 <p>A MessageDigest object starts out initialized. The data is 
 processed through it using the <a href="#update(byte)">update</a>
 methods. At any point <a href="#reset">reset</a> can be called
 to reset the digest. Once all the data to be updated has been
 updated, one of the <a href="#digest()">digest</a> methods should 
 be called to complete the hash computation.
 <p>The <code>digest</code> method can be called once for a given number 
 of updates. After <code>digest</code> has been called, the MessageDigest
 object is reset to its initialized state.
 <p>Implementations are free to implement the Cloneable interface,
 and doing so will let client applications test cloneability
 using <code>instanceof Cloneable</code> before cloning: <p>    
 <pre>
 MessageDigest md = MessageDigest.getInstance("SHA");
 if (md instanceof Cloneable) {
     md.update(toChapter1);
     MessageDigest tc1 = md.clone();
     byte[] toChapter1Digest = tc1.digest;
     md.update(toChapter2);
     ...etc.
 } else {
     throw new DigestException("couldn't make digest of partial content");
 }
 </pre>
 <p>Note that if a given implementation is not cloneable, it is
 still possible to compute intermediate digests by instantiating
 several instances, if the number of digests is known in advance.
<p>
<dl>
    <dt> <b>See Also:</b>
    <dd> <a href="java.security.DigestInputStream.html#_top_">DigestInputStream</a>, <a href="java.security.DigestOutputStream.html#_top_">DigestOutputStream</a>
</dl>
<hr>
<a name="index"></a>
<h2>
  <img src="images/constructor-index.gif" width=275 height=38 alt="Constructor Index">
</h2>
<dl>
  <dt> <img src="images/yellow-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#MessageDigest(java.lang.String)"><b>MessageDigest</b></a>(String)
  <dd>  Creates a message digest with the specified algorithm name.
</dl>
<h2>
  <img src="images/method-index.gif" width=207 height=38 alt="Method Index">
</h2>
<dl>
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#clone()"><b>clone</b></a>()
  <dd> 
 Returns a clone if the implementation is cloneable.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#digest()"><b>digest</b></a>()
  <dd>  Completes the hash computation by performing final operations
 such as padding.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#digest(byte[])"><b>digest</b></a>(byte[])
  <dd>  Performs a final update on the digest using the specified array 
 of bytes, then completes the digest computation.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#engineDigest()"><b>engineDigest</b></a>()
  <dd>  <b>SPI</b>: Completes the hash computation by performing final
 operations such as padding.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#engineReset()"><b>engineReset</b></a>()
  <dd>  <b>SPI</b>: Resets the digest for further use.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#engineUpdate(byte)"><b>engineUpdate</b></a>(byte)
  <dd>  <b>SPI</b>: Updates the digest using the specified byte.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#engineUpdate(byte[], int, int)"><b>engineUpdate</b></a>(byte[], int, int)
  <dd>  <b>SPI</b>: Updates the digest using the specified array of bytes,    
 starting at the specified offset.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getAlgorithm()"><b>getAlgorithm</b></a>()
  <dd> 
 Returns a string that identifies the algorithm, independent of
 implementation details.
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getInstance(java.lang.String)"><b>getInstance</b></a>(String)
  <dd>  Generates a MessageDigest object that implements the specified digest
 algorithm.
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#getInstance(java.lang.String, java.lang.String)"><b>getInstance</b></a>(String, String)
  <dd>  Generates a MessageDigest object implementing the specified
 algorithm, as supplied from the specified provider, if such an 
 algorithm is available from the provider.
  <dt> <img src="images/green-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#isEqual(byte[], byte[])"><b>isEqual</b></a>(byte[], byte[])
  <dd>  Compares two digests for equality.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#reset()"><b>reset</b></a>()
  <dd>  Resets the digest for further use.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#toString()"><b>toString</b></a>()
  <dd>  Returns a string representation of this message digest object.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#update(byte)"><b>update</b></a>(byte)
  <dd>  Updates the digest using the specified byte.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#update(byte[])"><b>update</b></a>(byte[])
  <dd>  Updates the digest using the specified array of bytes.
  <dt> <img src="images/red-ball-small.gif" width=6 height=6 alt=" o ">
	<a href="#update(byte[], int, int)"><b>update</b></a>(byte[], int, int)
  <dd>  Updates the digest using the specified array of bytes, starting
 at the specified offset.
</dl>
<a name="constructors"></a>
<h2>
  <img src="images/constructors.gif" width=231 height=38 alt="Constructors">
</h2>
<a name="MessageDigest"></a>
<a name="MessageDigest(java.lang.String)"><img src="images/yellow-ball.gif" width=12 height=12 alt=" o "></a>
<b>MessageDigest</b>
<pre>
 protected MessageDigest(<a href="java.lang.String.html#_top_">String</a> algorithm)
</pre>
<dl>
  <dd> Creates a message digest with the specified algorithm name.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> algorithm - the standard name of the digest algorithm.
 See Appendix A in the <a href=
 "../guide/security/CryptoSpec.html#AppA">
 Java Cryptography Architecture API Specification &amp; Reference </a> 
 for information about standard algorithm names.
  </dl></dd>
</dl>
<a name="methods"></a>
<h2>
  <img src="images/methods.gif" width=151 height=38 alt="Methods">
</h2>
<a name="getInstance(java.lang.String)"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getInstance"><b>getInstance</b></a>
<pre>
 public static <a href="#_top_">MessageDigest</a> getInstance(<a href="java.lang.String.html#_top_">String</a> algorithm) throws <a href="java.security.NoSuchAlgorithmException.html#_top_">NoSuchAlgorithmException</a>
</pre>
<dl>
  <dd> Generates a MessageDigest object that implements the specified digest
 algorithm. If the default provider package contains a MessageDigest
 subclass implementing the algorithm, an instance of that subclass
 is returned. If the algorithm is not available in the default 
 package, other packages are searched.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> algorithm - the name of the algorithm requested.
 See Appendix A in the <a href=
 "../guide/security/CryptoSpec.html#AppA">
 Java Cryptography Architecture API Specification &amp; Reference </a> 
 for information about standard algorithm names.
    <dt> <b>Returns:</b>
    <dd> a Message Digest object implementing the specified
 algorithm.
    <dt> <b>Throws:</b> <a href="java.security.NoSuchAlgorithmException.html#_top_">NoSuchAlgorithmException</a>
    <dd> if the algorithm is
 not available in the caller's environment.
  </dl></dd>
</dl>
<a name="getInstance(java.lang.String, java.lang.String)"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getInstance"><b>getInstance</b></a>
<pre>
 public static <a href="#_top_">MessageDigest</a> getInstance(<a href="java.lang.String.html#_top_">String</a> algorithm,
                                         <a href="java.lang.String.html#_top_">String</a> provider) throws <a href="java.security.NoSuchAlgorithmException.html#_top_">NoSuchAlgorithmException</a>, <a href="java.security.NoSuchProviderException.html#_top_">NoSuchProviderException</a>
</pre>
<dl>
  <dd> Generates a MessageDigest object implementing the specified
 algorithm, as supplied from the specified provider, if such an 
 algorithm is available from the provider.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> algorithm - the name of the algorithm requested.
 See Appendix A in the <a href=
 "../guide/security/CryptoSpec.html#AppA">
 Java Cryptography Architecture API Specification &amp; Reference </a> 
 for information about standard algorithm names.
    <dd> provider - the name of the provider.
    <dt> <b>Returns:</b>
    <dd> a Message Digest object implementing the specified
 algorithm.
    <dt> <b>Throws:</b> <a href="java.security.NoSuchAlgorithmException.html#_top_">NoSuchAlgorithmException</a>
    <dd> if the algorithm is
 not available in the package supplied by the requested
 provider.
    <dt> <b>Throws:</b> <a href="java.security.NoSuchProviderException.html#_top_">NoSuchProviderException</a>
    <dd> if the provider is not
 available in the environment.
    <dt> <b>See Also:</b>
    <dd> <a href="java.security.Provider.html#_top_">Provider</a>
  </dl></dd>
</dl>
<a name="update(byte)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="update"><b>update</b></a>
<pre>
 public void update(byte input)
</pre>
<dl>
  <dd> Updates the digest using the specified byte.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the byte with which to update the digest.
  </dl></dd>
</dl>
<a name="update(byte[], int, int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="update"><b>update</b></a>
<pre>
 public void update(byte input[],
                    int offset,
                    int len)
</pre>
<dl>
  <dd> Updates the digest using the specified array of bytes, starting
 at the specified offset.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the array of bytes.
    <dd> offset - the offset to start from in the array of bytes.
    <dd> len - the number of bytes to use, starting at
 <code>offset</code>.
  </dl></dd>
</dl>
<a name="update(byte[])"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="update"><b>update</b></a>
<pre>
 public void update(byte input[])
</pre>
<dl>
  <dd> Updates the digest using the specified array of bytes.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the array of bytes.
  </dl></dd>
</dl>
<a name="digest()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="digest"><b>digest</b></a>
<pre>
 public byte[] digest()
</pre>
<dl>
  <dd> Completes the hash computation by performing final operations
 such as padding. The digest is reset after this call is made.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> the array of bytes for the resulting hash value.
  </dl></dd>
</dl>
<a name="digest(byte[])"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="digest"><b>digest</b></a>
<pre>
 public byte[] digest(byte input[])
</pre>
<dl>
  <dd> Performs a final update on the digest using the specified array 
 of bytes, then completes the digest computation. That is, this
 method first calls <a href = "#update(byte[])">update</a> on the
 array, then calls <a href = "#digest()">digest()</a>.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the input to be updated before the digest is
 completed.
    <dt> <b>Returns:</b>
    <dd> the array of bytes for the resulting hash value.
  </dl></dd>
</dl>
<a name="toString()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="toString"><b>toString</b></a>
<pre>
 public <a href="java.lang.String.html#_top_">String</a> toString()
</pre>
<dl>
  <dd> Returns a string representation of this message digest object.
<p>
  <dd><dl>
    <dt> <b>Overrides:</b>
    <dd> <a href="java.lang.Object.html#toString()">toString</a> in class <a href="java.lang.Object.html#_top_">Object</a>
  </dl></dd>
</dl>
<a name="isEqual(byte[], byte[])"><img src="images/green-ball.gif" width=12 height=12 alt=" o "></a>
<a name="isEqual"><b>isEqual</b></a>
<pre>
 public static boolean isEqual(byte digesta[],
                               byte digestb[])
</pre>
<dl>
  <dd> Compares two digests for equality. Does a simple byte compare.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> digesta - one of the digests to compare.
    <dd> digestb - the other digest to compare.
    <dt> <b>Returns:</b>
    <dd> true if the digests are equal, false otherwise.
  </dl></dd>
</dl>
<a name="reset()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="reset"><b>reset</b></a>
<pre>
 public void reset()
</pre>
<dl>
  <dd> Resets the digest for further use.
<p>
</dl>
<a name="getAlgorithm()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="getAlgorithm"><b>getAlgorithm</b></a>
<pre>
 public final <a href="java.lang.String.html#_top_">String</a> getAlgorithm()
</pre>
<dl>
  <dd> Returns a string that identifies the algorithm, independent of
 implementation details. The name should be a standard
 Java Security name (such as "SHA", "MD5", and so on). 
 See Appendix A in the <a href=
 "../guide/security/CryptoSpec.html#AppA">
 Java Cryptography Architecture API Specification &amp; Reference </a> 
 for information about standard algorithm names.
<p>
</dl>
<a name="engineUpdate(byte)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="engineUpdate"><b>engineUpdate</b></a>
<pre>
 protected abstract void engineUpdate(byte input)
</pre>
<dl>
  <dd> <b>SPI</b>: Updates the digest using the specified byte.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the byte to use for the update.
  </dl></dd>
</dl>
<a name="engineUpdate(byte[], int, int)"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="engineUpdate"><b>engineUpdate</b></a>
<pre>
 protected abstract void engineUpdate(byte input[],
                                      int offset,
                                      int len)
</pre>
<dl>
  <dd> <b>SPI</b>: Updates the digest using the specified array of bytes,    
 starting at the specified offset. This should be a no-op if
 the digest has been finalized.
<p>
  <dd><dl>
    <dt> <b>Parameters:</b>
    <dd> input - the array of bytes to use for the update.
    <dd> offset - the offset to start from in the array of bytes.
    <dd> len - the number of bytes to use, starting at
 <code>offset</code>.
  </dl></dd>
</dl>
<a name="engineDigest()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="engineDigest"><b>engineDigest</b></a>
<pre>
 protected abstract byte[] engineDigest()
</pre>
<dl>
  <dd> <b>SPI</b>: Completes the hash computation by performing final
 operations such as padding. Once <code>engineDigest</code> has 
 been called, the engine should be reset (see <a href =
 "#reset">reset</a>).  Resetting is the responsibility of the
 engine implementor.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> the array of bytes for the resulting hash value.
  </dl></dd>
</dl>
<a name="engineReset()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="engineReset"><b>engineReset</b></a>
<pre>
 protected abstract void engineReset()
</pre>
<dl>
  <dd> <b>SPI</b>: Resets the digest for further use.
<p>
</dl>
<a name="clone()"><img src="images/red-ball.gif" width=12 height=12 alt=" o "></a>
<a name="clone"><b>clone</b></a>
<pre>
 public <a href="java.lang.Object.html#_top_">Object</a> clone() throws <a href="java.lang.CloneNotSupportedException.html#_top_">CloneNotSupportedException</a>
</pre>
<dl>
  <dd> Returns a clone if the implementation is cloneable.
<p>
  <dd><dl>
    <dt> <b>Returns:</b>
    <dd> a clone if the implementation is cloneable.
    <dt> <b>Throws:</b> <a href="java.lang.CloneNotSupportedException.html#_top_">CloneNotSupportedException</a>
    <dd> if this is called on an
 implementation that does not support <code>Cloneable</code>.
    <dt> <b>Overrides:</b>
    <dd> <a href="java.lang.Object.html#clone()">clone</a> in class <a href="java.lang.Object.html#_top_">Object</a>
  </dl></dd>
</dl>
<hr>
<pre>
<a href="packages.html">All Packages</a>  <a href="tree.html">Class Hierarchy</a>  <a href="Package-java.security.html">This Package</a>  <a href="java.security.KeyPairGenerator.html#_top_">Previous</a>  <a href="java.security.Provider.html#_top_">Next</a>  <a href="AllNames.html">Index</a></pre>
</body>
</html>
