Ostermillerutil Java Utilities MD5 - com.Ostermiller.util Java Utilities

MD5 is a cryptographic one way hash algorithm. These classes compute MD5 for Java Strings, byte arrays, or streams. MD5 is now considered a weak algorithm. New applications should consider more secure one way hashes.

Example

System.out.println(
    MD5.getHashString(
        "Hello World"
    )
);

Security Alert

The MD5 class had a bug in version 1.02.23 and earlier that miscalculated MD5 sums for inputs of certain odd byte lengths. Please consider the implications for your application and upgrade to the most recent version.

This class takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. 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.

This class is based on work by Santeri Paavolainen. and RFC1321. This implementation is several times faster and much more memory efficient than Santeri's implementation.


Example

// Print the MD5 hash for a line
// read from standard input
MD5InputStream in = new MD5InputStream(System.in);
int b;
while ((b = in.read()) != -1 && b != '\r' && b != '\n');
System.out.println(in.getHashString());

Input Stream

A filtered input stream that computes an MD5 sum for anything read.


Example

// Write out hello world
// and print its MD5 hash 
MD5OutputStream out = new MD5OutputStream(System.out);
out.write("Hello World\n".getBytes());
System.out.println(out.getHashString());

Output Stream

A filtered output stream that computes an MD5 sum for anything written.



License

OstermillerUtil Java Utilities Copyright (c) 2001-2020 by Stephen Ostermiller and other contributors

The OstermillerUtils library is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

License FAQs - Why GPL? How about the LGPL or something else?