es.prodevelop.gvsig.mobile.fmap.util.md5
Class MD5

java.lang.Object
  extended byes.prodevelop.gvsig.mobile.fmap.util.md5.MD5

public class MD5
extends java.lang.Object

* Modfied By: * Prodevelop Integración de Tecnologías SL * Conde Salvatierra de Álava , 34-10 * 46004 Valencia * Spain * * +34 963 510 612 * +34 963 510 968 * gis@prodevelop.es * http://www.prodevelop.es * * gvSIG Mobile Team 2006 * *


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.
 byte[] Final()
          Returns array of bytes (16 bytes) representing hash as of the current state of this object.
static byte[] getHash(java.io.File f)
          Calculates and returns the hash of the contents of the given file.
static boolean hashesEqual(byte[] hash1, byte[] hash2)
           
 void Init()
          Initialize MD5 internal state (object can be reused just by calling Init() after every Final()
 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(MD5State stat, 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
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MD5

public MD5()
Class constructor


MD5

public MD5(java.lang.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 void Init()
Initialize MD5 internal state (object can be reused just by calling Init() after every Final()


Update

public void Update(MD5State stat,
                   byte[] buffer,
                   int offset,
                   int length)
Updates hash with the bytebuffer given (using at maximum length bytes from that buffer)

Parameters:
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)

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 void Update(java.lang.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.

Parameters:
s - String to be update to hash (is used as s.getBytes())

Update

public void Update(java.lang.String s,
                   java.lang.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.

Parameters:
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.
Throws:
java.io.UnsupportedEncodingException - If the named charset is not supported.

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 java.lang.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 java.lang.String asHex()
Returns 32-character hex representation of this objects hash

Returns:
String of this object's hash

getHash

public static byte[] getHash(java.io.File f)
                      throws java.io.IOException
Calculates and returns the hash of the contents of the given file.

Throws:
java.io.IOException

hashesEqual

public static boolean hashesEqual(byte[] hash1,
                                  byte[] hash2)
Returns:
true iff the first 16 bytes of both hash1 and hash2 are equal; both hash1 and hash2 are null; or either hash array is less than 16 bytes in length and their lengths and all of their bytes are equal.