java.lang.Object
com.aoapps.hodgepodge.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>
  • Constructor Summary

    Constructors
    Constructor
    Description
    MD5()
    Class constructor.
    MD5(Object ob)
    Initialize class, and update hash with ob.toString()
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns 32-character hex representation of this objects hash.
    static String
    asHex(byte[] hash)
    Turns array of bytes into string representing each byte as unsigned hex number.
    byte[]
    Returns array of bytes (16 bytes) representing hash as of the current state of this object.
    final byte[]
    Deprecated.
    Please use digest() instead.
    static long
    getMD5Hi(byte[] md5)
     
    static long
     
    static long
    getMD5Lo(byte[] md5)
     
    static long
     
    static String
    getMD5String(long md5Hi, long md5Lo)
     
    final void
    Initialize MD5 internal state (object can be reused just by calling init() after every digest().
    final void
    Deprecated.
    Please use init() instead.
    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).
    final void
    Update buffer with given string.
    final void
    Update(byte b)
    Deprecated.
    Please use update(byte) instead.
    final void
    Update(byte[] buffer)
    Deprecated.
    Please use update(byte[]) instead.
    final void
    Update(byte[] buffer, int length)
    Deprecated.
    Please use update(byte[], int) instead.
    final void
    Update(byte[] buffer, int offset, int length)
    Deprecated.
    Please use update(byte[], int, int) instead.
    final void
    Update(int i)
    Deprecated.
    Please use update(int) instead.
    final void
    Deprecated.
    Please use update(java.lang.String) instead.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • 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 Details

    • init

      public final void init()
      Initialize MD5 internal state (object can be reused just by calling init() after every digest().
    • Init

      @Deprecated public final void Init()
      Deprecated.
      Please use init() instead.
      Initialize MD5 internal state (object can be reused just by calling init() after every digest().
    • update

      public void update(byte[] buffer, int offset, int length)
      Plain update, updates this object.
    • Update

      @Deprecated public final void Update(byte[] buffer, int offset, int length)
      Deprecated.
      Please use update(byte[], int, int) instead.
    • update

      public void update(byte[] buffer, int length)
    • Update

      @Deprecated public final void Update(byte[] buffer, int length)
      Deprecated.
      Please use update(byte[], int) instead.
    • 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

      @Deprecated public final void Update(byte[] buffer)
      Deprecated.
      Please use update(byte[]) instead.
      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

      @Deprecated public final void Update(byte b)
      Deprecated.
      Please use update(byte) instead.
      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

      @Deprecated public final void Update(String s)
      Deprecated.
      Please use update(java.lang.String) instead.
      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
    • Update

      @Deprecated public final void Update(int i)
      Deprecated.
      Please use update(int) instead.
      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
    • digest

      public byte[] digest()
      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
    • Final

      @Deprecated public final byte[] Final()
      Deprecated.
      Please use digest() instead.
      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 md5Hi, long md5Lo)
    • 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