
Public Member Functions | |
| synchronized void | Init () |
| MD5 () | |
| MD5 (Object ob) | |
| void | Update (MD5State stat, byte buffer[], int offset, int length) |
| void | Update (byte buffer[], int offset, int length) |
| void | Update (byte buffer[], int length) |
| void | Update (byte buffer[]) |
| void | Update (byte b) |
| void | Update (String s) |
| void | Update (String s, String charset_name) throws java.io.UnsupportedEncodingException |
| void | Update (int i) |
| synchronized byte[] | Final () |
| String | asHex () |
Static Public Member Functions | |
| static String | asHex (byte hash[]) |
| static synchronized final void | initNativeLibrary (boolean disallow_lib_loading) |
Package Attributes | |
| MD5State | state |
| MD5State | finals |
Static Package Attributes | |
| static byte | padding [] |
Originally written by Santeri Paavolainen, Helsinki Finland 1996.
(c) Santeri Paavolainen, Helsinki Finland 1996
Many changes Copyright (c) 2002 Timothy W Macinta
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License along with this library; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
See http://www.twmacinta.com/myjava/fast_md5.php for more information on this file and the related files.
This was originally a rather straight re-implementation of the reference implementation given in RFC1321 by RSA. It passes the MD5 test suite as defined in RFC1321.
Many optimizations made by Timothy W Macinta. Reduced time to checksum a test file in Java alone to roughly half the time taken compared with java.security.MessageDigest (within an intepretter). Also added an optional native method to reduce the time even further. See http://www.twmacinta.com/myjava/fast_md5.php for further information on the time improvements achieved.
Some bug fixes also made by Timothy W Macinta.
Please note: I (Timothy Macinta) have put this code in the com.twmacinta.util package only because it came without a package. I was not the the original author of the code, although I did optimize it (substantially) and fix some bugs.
This Java class has been derived from the RSA Data Security, Inc. MD5 Message-Digest Algorithm and its reference implementation.
This class will attempt to use a native method to quickly compute checksums when the appropriate native library is available. On Linux, this library should be named "MD5.so" and on Windows it should be named "MD5.dll". The code will attempt to locate the library in the following locations in the order given:
If the library is not found, the code will fall back to the default (slower) Java code.
As a side effect of having the code search for the native library, SecurityExceptions might be thrown on JVMs that have a restrictive SecurityManager. The initialization code attempts to silently discard these exceptions and continue, but many SecurityManagers will attempt to notify the user directly of all SecurityExceptions thrown. Consequently, the code has provisions for skipping the search for the native library. Any of these provisions may be used to skip the search as long as they are performed before the first instance of a com.twmacinta.util.MD5 object is constructed (note that the convenience stream objects will implicitly create an MD5 object).
The first option is to set the system property "com.twmacinta.util.MD5.NO_NATIVE_LIB" to "true" or "1". Unfortunately, SecurityManagers may also choose to disallow system property setting, so this won't be of use in all cases.
The second option is to call com.twmacinta.util.MD5.initNativeLibrary(false) before any MD5 objects are constructed.
Definition at line 113 of file MD5.java.
| org.osmius.util.MD5.MD5 | ( | Object | ob | ) |
Initialize class, and update hash with ob.toString()
| ob | Object, ob.toString() is used to update hash after initialization |
Definition at line 161 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| synchronized void org.osmius.util.MD5.Init | ( | ) |
Initialize MD5 internal state (object can be reused just by calling Init() after every Final()
Definition at line 141 of file MD5.java.
References org.osmius.util.MD5.finals, and org.osmius.util.MD5.state.
Referenced by org.osmius.util.MD5Utils.getMD5().
| void org.osmius.util.MD5.Update | ( | MD5State | stat, | |
| byte | buffer[], | |||
| int | offset, | |||
| int | length | |||
| ) |
Updates hash with the bytebuffer given (using at maximum length bytes from that buffer)
| stat | Which state is updated | |
| buffer | Array of bytes to be hashed | |
| offset | Offset to buffer array | |
| length | Use at maximum `length' bytes (absolute maximum is buffer.length) |
Definition at line 414 of file MD5.java.
References org.osmius.util.MD5State.buffer, org.osmius.util.MD5State.count, org.osmius.util.MD5.finals, and org.osmius.util.MD5State.state.
Referenced by org.osmius.util.MD5.Final(), org.osmius.util.MD5Utils.getMD5(), org.osmius.util.MD5.MD5(), and org.osmius.util.MD5.Update().
| void org.osmius.util.MD5.Update | ( | byte | buffer[], | |
| int | offset, | |||
| int | length | |||
| ) |
Plain update, updates this object
Definition at line 482 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| void org.osmius.util.MD5.Update | ( | byte | buffer[] | ) |
Updates hash with given array of bytes
| buffer | Array of bytes to use for updating the hash |
Definition at line 495 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| void org.osmius.util.MD5.Update | ( | byte | b | ) |
Updates hash with a single byte
| b | Single byte to update the hash |
Definition at line 504 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| void org.osmius.util.MD5.Update | ( | String | s | ) |
Update buffer with given string. Note that because the version of the s.getBytes() method without parameters is used to convert the string to a byte array, the results of this method may be different on different platforms. The s.getBytes() method converts the string into a byte array using the current platform's default character set and may therefore have different results on platforms with different default character sets. If a version that works consistently across platforms with different default character sets is desired, use the overloaded version of the Update() method which takes a string and a character encoding.
| s | String to be update to hash (is used as s.getBytes()) |
Definition at line 524 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| void org.osmius.util.MD5.Update | ( | String | s, | |
| String | charset_name | |||
| ) | throws java.io.UnsupportedEncodingException |
Update buffer with given string using the given encoding. If the given encoding is null, the encoding "ISO8859_1" is used.
| s | String to be update to hash (is used as s.getBytes(charset_name)) | |
| charset_name | The character set to use to convert s to a byte array, or null if the "ISO8859_1" character set is desired. |
| java.io.UnsupportedEncodingException | If the named charset is not supported. |
Definition at line 540 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| void org.osmius.util.MD5.Update | ( | int | i | ) |
Update buffer with a single integer (only & 0xff part is used, as a byte)
| i | Integer value, which is then converted to byte as i & 0xff |
Definition at line 554 of file MD5.java.
References org.osmius.util.MD5.Update().
Here is the call graph for this function:

| synchronized byte [] org.osmius.util.MD5.Final | ( | ) |
Returns array of bytes (16 bytes) representing hash as of the current state of this object. Note: getting a hash does not invalidate the hash object, it only creates a copy of the real state which is finalized.
Definition at line 581 of file MD5.java.
References org.osmius.util.MD5State.count, org.osmius.util.MD5.finals, org.osmius.util.MD5.padding, org.osmius.util.MD5State.state, and org.osmius.util.MD5.Update().
Referenced by org.osmius.util.MD5.asHex(), and org.osmius.util.MD5Utils.getMD5().
Here is the call graph for this function:

| static String org.osmius.util.MD5.asHex | ( | byte | hash[] | ) | [static] |
| String org.osmius.util.MD5.asHex | ( | ) |
Returns 32-character hex representation of this objects hash
Definition at line 632 of file MD5.java.
References org.osmius.util.MD5.Final().
Here is the call graph for this function:

MD5State org.osmius.util.MD5.state [package] |
MD5State org.osmius.util.MD5.finals [package] |
If Final() has been called, finals is set to the current finals state. Any Update() causes this to be set to null.
Definition at line 123 of file MD5.java.
Referenced by org.osmius.util.MD5.Final(), org.osmius.util.MD5.Init(), and org.osmius.util.MD5.Update().
byte org.osmius.util.MD5.padding[] [static, package] |
Initial value:
{(byte) 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0}
Definition at line 128 of file MD5.java.
Referenced by org.osmius.util.MD5.Final().
1.5.1