Package com.aoindustries.md5
Class MD5
- java.lang.Object
-
- com.aoindustries.md5.MD5
-
public class MD5 extends Object
Implementation of RSA's MD5 hash generator- Version:
- $Revision: 1.2 $
- Author:
- Santeri Paavolainen <sjpaavol@cc.helsinki.fi>
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringasHex()Returns 32-character hex representation of this objects hashstatic StringasHex(byte[] hash)Turns array of bytes into string representing each byte as unsigned hex number.byte[]Final()Returns array of bytes (16 bytes) representing hash as of the current state of this object.static longgetMD5Hi(byte[] md5)static longgetMD5Hi(String md5)static longgetMD5Lo(byte[] md5)static longgetMD5Lo(String md5)static StringgetMD5String(long md5_hi, long md5_lo)voidInit()Initialize MD5 internal state (object can be reused just by calling Init() after every Final()voidUpdate(byte b)Updates hash with a single bytevoidUpdate(byte[] buffer)Updates hash with given array of bytesvoidUpdate(byte[] buffer, int length)voidUpdate(byte[] buffer, int offset, int length)Plain update, updates this objectvoidUpdate(int i)Update buffer with a single integer (only & 0xff part is used, as a byte)voidUpdate(String s)Update buffer with given string.
-
-
-
Constructor Detail
-
MD5
public MD5()
Class constructor
-
MD5
public MD5(Object ob)
Initialize class, and update hash with ob.toString()- Parameters:
ob- Object, ob.toString() is used to update hash after initialization
-
-
Method Detail
-
Init
public final void Init()
Initialize MD5 internal state (object can be reused just by calling Init() after every Final()
-
Update
public void Update(byte[] buffer, int offset, int length)Plain update, updates this object
-
Update
public void Update(byte[] buffer, int length)
-
Update
public void Update(byte[] buffer)
Updates hash with given array of bytes- Parameters:
buffer- Array of bytes to use for updating the hash
-
Update
public void Update(byte b)
Updates hash with a single byte- Parameters:
b- Single byte to update the hash
-
Update
public final void Update(String s)
Update buffer with given string.- Parameters:
s- String to be update to hash (is used as s.getBytes())
-
Update
public void Update(int i)
Update buffer with a single integer (only & 0xff part is used, as a byte)- Parameters:
i- Integer value, which is then converted to byte as i & 0xff
-
Final
public byte[] 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.- Returns:
- Array of 16 bytes, the hash of all updated bytes
-
asHex
public static String asHex(byte[] hash)
Turns array of bytes into string representing each byte as unsigned hex number.- Parameters:
hash- Array of bytes to convert to hex-string- Returns:
- Generated hex string
-
asHex
public String asHex()
Returns 32-character hex representation of this objects hash- Returns:
- String of this object's hash
-
getMD5String
public static String getMD5String(long md5_hi, long md5_lo)
-
getMD5Hi
public static long getMD5Hi(byte[] md5)
-
getMD5Hi
public static long getMD5Hi(String md5) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
getMD5Lo
public static long getMD5Lo(byte[] md5)
-
getMD5Lo
public static long getMD5Lo(String md5) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
-