|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.jfx.md5.MD5
public class MD5
Fast implementation of RSA's MD5 hash generator in Java JDK Beta-2 or higher
Originally written by Santeri Paavolainen, Helsinki Finland 1996
(c) Santeri Paavolainen, Helsinki Finland 1996
Some 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.cs.hut.fi/~santtu/java/ for more information on this class.
This is rather straight re-implementation of the reference implementation given in RFC1321 by RSA.
Passes MD5 test suite as defined in RFC1321.
Some optimizations made by Timothy W Macinta. Reduced time to checksum a test file from 1m31.210s to 0m14.300s. This is roughly twice as fast as using java.security.MessageDigest which takes 0m28.900s. For further optimization, the Transform() and Decode() methods are natural choices for re-implementation using native methods.
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.
Constructor Summary | |
---|---|
MD5()
Class constructor |
|
MD5(java.lang.Object ob)
Initialize class, and update hash with ob.toString() |
Method Summary | |
---|---|
java.lang.String |
asHex()
Returns 32-character hex representation of this objects hash |
static java.lang.String |
asHex(byte[] hash)
Turns array of bytes into string representing each byte as unsigned hex number. |
static java.lang.String |
asHex(byte[] hash,
int offset,
int length)
|
byte[] |
Final()
Returns array of bytes (16 bytes) representing hash as of the current state of this object. |
void |
Init()
Initialize MD5 internal state (object can be reused just by calling Init() after every Final() |
static java.lang.String |
MD5(byte[] input)
|
static java.lang.String |
MD5(java.lang.String input)
|
static java.lang.String |
MD5(java.lang.String input,
java.lang.String encoding)
|
void |
Update(byte b)
Updates hash with a single byte |
void |
Update(byte[] buffer)
Updates hash with given array of bytes |
void |
Update(byte[] buffer,
int length)
|
void |
Update(byte[] buffer,
int offset,
int length)
Plain update, updates this object |
void |
Update(int i)
Update buffer with a single integer (only & 0xff part is used, as a byte) |
void |
Update(com.jfx.md5.MD5State state,
byte[] buffer,
int offset,
int length)
Updates hash with the bytebuffer given (using at maximum length bytes from that buffer) |
void |
Update(java.lang.String s)
Update buffer with given string. |
void |
Update(java.lang.String s,
java.lang.String charset_name)
Update buffer with given string using the given encoding. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public MD5()
public MD5(java.lang.Object ob)
ob
- Object, ob.toString() is used to update hash
after initializationMethod Detail |
---|
public void Init()
public static java.lang.String MD5(java.lang.String input)
public static java.lang.String MD5(java.lang.String input, java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public static java.lang.String MD5(byte[] input)
public void Update(com.jfx.md5.MD5State state, byte[] buffer, int offset, int length)
state
- Which state is updatedbuffer
- Array of bytes to be hashedoffset
- Offset to buffer arraylength
- Use at maximum `length' bytes (absolute
maximum is buffer.length)public void Update(byte[] buffer, int offset, int length)
public void Update(byte[] buffer, int length)
public void Update(byte[] buffer)
buffer
- Array of bytes to use for updating the hashpublic void Update(byte b)
b
- Single byte to update the hashpublic void Update(java.lang.String s)
s
- String to be update to hash (is used as
s.getBytes())public void Update(java.lang.String s, java.lang.String charset_name) throws java.io.UnsupportedEncodingException
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.public void Update(int i)
i
- Integer value, which is then converted to
byte as i & 0xffpublic byte[] Final()
public static java.lang.String asHex(byte[] hash)
hash
- Array of bytes to convert to hex-string
public static java.lang.String asHex(byte[] hash, int offset, int length)
public java.lang.String asHex()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |