com.antiaction.digest
Class MD5

java.lang.Object
  |
  +--com.antiaction.digest.MD5

public class MD5
extends java.lang.Object

Java implementation of the MD5 digest algorithm described in rfc1321. Based on the reference implementation in C.

Version:
1.00
Author:
Nicholas Clarke

Field Summary
protected  byte[] buffer
          Buffer for mid block processing.
protected  int bufferedbytes
          Buffered bytes from previous call.
protected  long count
          Processed bit count.
protected static java.lang.String hexList
          Hexadecimal conversion tabel.
protected static byte[] PADDING
          Padding tabel used to block data.
protected static int S11
          Constant for MD5Transform routine.
protected static int S12
          Constant for MD5Transform routine.
protected static int S13
          Constant for MD5Transform routine.
protected static int S14
          Constant for MD5Transform routine.
protected static int S21
          Constant for MD5Transform routine.
protected static int S22
          Constant for MD5Transform routine.
protected static int S23
          Constant for MD5Transform routine.
protected static int S24
          Constant for MD5Transform routine.
protected static int S31
          Constant for MD5Transform routine.
protected static int S32
          Constant for MD5Transform routine.
protected static int S33
          Constant for MD5Transform routine.
protected static int S34
          Constant for MD5Transform routine.
protected static int S41
          Constant for MD5Transform routine.
protected static int S42
          Constant for MD5Transform routine.
protected static int S43
          Constant for MD5Transform routine.
protected static int S44
          Constant for MD5Transform routine.
protected  int[] state
          Transformation states.
protected  int[] x
          Temporary transformation data.
 
Constructor Summary
MD5()
          Initialize object and state.
 
Method Summary
static void Decode(int[] output, byte[] input, int offset, int len)
          Decodes input (unsigned char) into output (UINT4).
static void Encode(byte[] output, int[] input, int len)
          Encodes input (UINT4) into output (unsigned char).
protected static int F(int x, int y, int z)
          Basic MD5 function.
protected static int FF(int a, int b, int c, int d, int x, int s, int ac)
          Transformations for rounds 1, 2, 3, and 4.
 void Final(byte[] digest)
          MD5 finalization.
protected static int G(int x, int y, int z)
          Basic MD5 function.
protected static int GG(int a, int b, int c, int d, int x, int s, int ac)
          Transformations for rounds 1, 2, 3, and 4.
protected static int H(int x, int y, int z)
          Basic MD5 function.
protected static int HH(int a, int b, int c, int d, int x, int s, int ac)
          Transformations for rounds 1, 2, 3, and 4.
protected static int I(int x, int y, int z)
          Basic MD5 function.
protected static int II(int a, int b, int c, int d, int x, int s, int ac)
          Transformations for rounds 1, 2, 3, and 4.
 void Init()
          Initialize state and all internal data structures.
static java.lang.String MDFile(java.io.File infile)
          Returns the message digest of the file content.
static java.lang.String MDFile(java.lang.String fname)
          Returns the message digest of the file content.
static java.lang.String MDString(byte[] digest)
          Returns the string representation of a message digest.
static java.lang.String MDString(java.lang.String s)
          Returns the message digest of the string argument.
protected static int ROTATE_LEFT(int x, int n)
          ROTATE_LEFT rotates x left n bits.
protected  void Transform(byte[] block, int offset)
          MD5 basic transformation.
 void Update(byte[] input, int inputOffset, int inputLen)
          MD5 block update operation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hexList

protected static final java.lang.String hexList
Hexadecimal conversion tabel.

S11

protected static final int S11
Constant for MD5Transform routine.

S12

protected static final int S12
Constant for MD5Transform routine.

S13

protected static final int S13
Constant for MD5Transform routine.

S14

protected static final int S14
Constant for MD5Transform routine.

S21

protected static final int S21
Constant for MD5Transform routine.

S22

protected static final int S22
Constant for MD5Transform routine.

S23

protected static final int S23
Constant for MD5Transform routine.

S24

protected static final int S24
Constant for MD5Transform routine.

S31

protected static final int S31
Constant for MD5Transform routine.

S32

protected static final int S32
Constant for MD5Transform routine.

S33

protected static final int S33
Constant for MD5Transform routine.

S34

protected static final int S34
Constant for MD5Transform routine.

S41

protected static final int S41
Constant for MD5Transform routine.

S42

protected static final int S42
Constant for MD5Transform routine.

S43

protected static final int S43
Constant for MD5Transform routine.

S44

protected static final int S44
Constant for MD5Transform routine.

PADDING

protected static final byte[] PADDING
Padding tabel used to block data.

state

protected int[] state
Transformation states.

count

protected long count
Processed bit count.

x

protected int[] x
Temporary transformation data.

buffer

protected byte[] buffer
Buffer for mid block processing.

bufferedbytes

protected int bufferedbytes
Buffered bytes from previous call.
Constructor Detail

MD5

public MD5()
Initialize object and state.
Method Detail

F

protected static int F(int x,
                       int y,
                       int z)
Basic MD5 function.

G

protected static int G(int x,
                       int y,
                       int z)
Basic MD5 function.

H

protected static int H(int x,
                       int y,
                       int z)
Basic MD5 function.

I

protected static int I(int x,
                       int y,
                       int z)
Basic MD5 function.

ROTATE_LEFT

protected static int ROTATE_LEFT(int x,
                                 int n)
ROTATE_LEFT rotates x left n bits.
Parameters:
x - integer to rotate.
n - positions to rotate.
Returns:
rotated integer.

FF

protected static int FF(int a,
                        int b,
                        int c,
                        int d,
                        int x,
                        int s,
                        int ac)
Transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation.

GG

protected static int GG(int a,
                        int b,
                        int c,
                        int d,
                        int x,
                        int s,
                        int ac)
Transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation.

HH

protected static int HH(int a,
                        int b,
                        int c,
                        int d,
                        int x,
                        int s,
                        int ac)
Transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation.

II

protected static int II(int a,
                        int b,
                        int c,
                        int d,
                        int x,
                        int s,
                        int ac)
Transformations for rounds 1, 2, 3, and 4. Rotation is separate from addition to prevent recomputation.

Decode

public static void Decode(int[] output,
                          byte[] input,
                          int offset,
                          int len)
Decodes input (unsigned char) into output (UINT4). Assumes len is a multiple of 4.
Parameters:
output - integer array where converted data is stored.
input - byte array with source data.
offset - offset in source data.
len - length of data to convert.
Returns:
decoded data.

Encode

public static void Encode(byte[] output,
                          int[] input,
                          int len)
Encodes input (UINT4) into output (unsigned char). Assumes len is a multiple of 4.
Parameters:
output - array of bytes where converted data is stored.
input - integer array with source data.
offset - offset in source data.
len - length of data to convert.
Returns:
encoded data.

Transform

protected void Transform(byte[] block,
                         int offset)
MD5 basic transformation. Transforms state based on block.
Parameters:
block - data to transform.
offset - offset in data.

Init

public void Init()
Initialize state and all internal data structures.
See Also:
Update(byte[], int, int), Final(byte[])

Update

public void Update(byte[] input,
                   int inputOffset,
                   int inputLen)
MD5 block update operation. Continues an MD5 message-digest operation, processing another message block, and updating the context.
Parameters:
input - byte array of in data.
inputOffset - starting offset.
inputLen - length of data to digest.
See Also:
Init(), Final(byte[])

Final

public void Final(byte[] digest)
MD5 finalization. Ends an MD5 message-digest operation, writing the the message digest and zeroizing the context.
Parameters:
digest - array where the digest is to be placed.
See Also:
Init(), Update(byte[], int, int)

MDString

public static java.lang.String MDString(byte[] digest)
Returns the string representation of a message digest.
Parameters:
digest - byte array containing a message digest.
Returns:
the string representation of a message digest.

MDString

public static java.lang.String MDString(java.lang.String s)
Returns the message digest of the string argument.
Parameters:
s - string to digest.
Returns:
the message digest of the string argument.

MDFile

public static java.lang.String MDFile(java.lang.String fname)
Returns the message digest of the file content.
Parameters:
fname - filename.
Returns:
the message digest of the file content.

MDFile

public static java.lang.String MDFile(java.io.File infile)
Returns the message digest of the file content.
Parameters:
infile - File handle.
Returns:
the message digest of the file content.