com.Ostermiller.util
Class MD5OutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by java.io.FilterOutputStream
          extended by com.Ostermiller.util.MD5OutputStream
All Implemented Interfaces:
java.io.Closeable, java.io.Flushable

public class MD5OutputStream
extends java.io.FilterOutputStream

Implements MD5 functionality on a stream. More information about this class is available from ostermiller.org.

This class produces a 128-bit "fingerprint" or "message digest" for all data written to this stream. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given pre-specified target message digest. The MD5 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being encrypted with a private (secret) key under a public-key cryptosystem such as RSA.

For more information see RFC1321.

Since:
ostermillerutils 1.00.00
Author:
Santeri Paavolainen http://www.helsinki.fi/~sjpaavol/programs/md5/, Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities
See Also:
MD5, MD5InputStream

Field Summary
 
Fields inherited from class java.io.FilterOutputStream
out
 
Constructor Summary
MD5OutputStream(java.io.OutputStream out)
          Creates MD5OutputStream
 
Method Summary
 byte[] getHash()
          Returns array of bytes representing hash of the stream so far.
 java.lang.String getHashString()
          Get a 32-character hex representation representing hash of the stream so far.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting a offset off to this output stream.
 void write(int b)
          Writes the specified byte to this output stream.
 
Methods inherited from class java.io.FilterOutputStream
close, flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5OutputStream

public MD5OutputStream(java.io.OutputStream out)
Creates MD5OutputStream

Parameters:
out - The output stream
Since:
ostermillerutils 1.00.00
Method Detail

write

public void write(int b)
           throws java.io.IOException
Writes the specified byte to this output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the byte.
Throws:
java.io.IOException - if an I/O error occurs.
Since:
ostermillerutils 1.00.00

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Writes len bytes from the specified byte array starting a offset off to this output stream.

Overrides:
write in class java.io.FilterOutputStream
Parameters:
b - the data.
off - the start offset in the data.
len - the number of bytes to write.
Throws:
java.io.IOException - if an I/O error occurs.
Since:
ostermillerutils 1.00.00

getHash

public byte[] getHash()
Returns array of bytes representing hash of the stream so far.

Returns:
Array of 16 bytes, the hash of all written bytes.
Since:
ostermillerutils 1.00.00

getHashString

public java.lang.String getHashString()
Get a 32-character hex representation representing hash of the stream so far.

Returns:
A string containing the hash of all written bytes.
Since:
ostermillerutils 1.00.00


Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.