Package com.Ostermiller.util
Class MD5InputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.Ostermiller.util.MD5InputStream
- All Implemented Interfaces:
Closeable,AutoCloseable
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 read from 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://santtu.iki.fi/programs/md5/, Stephen Ostermiller https://ostermiller.org/contact.pl?regarding=Java+Utilities
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getHash()Returns array of bytes representing hash of the stream so far.Get a 32-character hex representation representing hash of the stream so far.intread()Reads the next byte of data from this input stream.intread(byte[] bytes, int offset, int length) Reads up to length bytes of data from this input stream into an array of bytes.Methods inherited from class java.io.FilterInputStream
available, close, mark, markSupported, read, reset, skipMethods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
MD5InputStream
Creates a MD5InputStream- Parameters:
in- the underlying input stream
-
-
Method Details
-
read
Reads the next byte of data from this input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input data is available, the end of the stream is detected, or an exception is thrown.This method simply performs in.read() and returns the result.
- Overrides:
readin classFilterInputStream- Returns:
- the next byte of data, or -1 if the end of the stream is reached.
- Throws:
IOException- if an I/O error occurs.- Since:
- ostermillerutils 1.00.00
-
read
Reads up to length bytes of data from this input stream into an array of bytes. This method blocks until some input is available.- Overrides:
readin classFilterInputStream- Parameters:
bytes- the buffer into which the data is read.offset- the start offset of the data.length- the maximum number of bytes read.- Throws:
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 read bytes.
- Since:
- ostermillerutils 1.00.00
-
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
-