MD2public final class MD2 extends MessageDigest Implements the MD2 hashing algorithm as described in IETF RFC 1321
(see http://www.ietf.org/rfc/rfc1321.txt) |
Fields Summary |
---|
private int[] | numState needed for MD2 hash. | private byte[] | dataState needed for MD2 hash. | private int[] | cksmState needed for MD2 hash. | private int[] | stateState needed for MD2 hash. |
Constructors Summary |
---|
MD2()Create an MD2 digest object.
reset();
|
Methods Summary |
---|
public java.lang.Object | clone()Clones the MessageDigest object.
MD2 cpy = new MD2();
System.arraycopy(this.state, 0, cpy.state, 0, 16);
System.arraycopy(this.num, 0, cpy.num, 0, 1);
System.arraycopy(this.cksm, 0, cpy.cksm, 0, 16);
System.arraycopy(this.data, 0, cpy.data, 0, 16);
return cpy;
| public int | digest(byte[] buf, int offset, int len)Completes the hash computation by performing final operations
such as padding. The digest is reset after this call is made.
if (len < getDigestLength()) {
throw new DigestException("Buffer too short.");
}
// check the parameters to prevent a VM crash
int test = buf[offset] + buf[offset + getDigestLength() - 1];
nativeFinal(null, 0, 0, buf, offset, state, num, cksm, data);
return getDigestLength();
| public java.lang.String | getAlgorithm()Gets the message digest algorithm.
return "MD2";
| public int | getDigestLength()Gets the length (in bytes) of the hash.
return 16;
| private static native void | nativeFinal(byte[] inBuf, int inOff, int inLen, byte[] outBuf, int outOff, int[] state, int[] num, int[] cksm, byte[] data)Generates a hash of all/last input data. Completes and returns the
hash compuatation after performing final operations such as padding.
The MessageDigest object is reset after this call.
| private static native void | nativeUpdate(byte[] inBuf, int inOff, int inLen, int[] state, int[] num, int[] cksm, byte[] data)Accumulates a hash of the input data. Continues an MD2
message-digest operation, processing another message
block, and updating the internal context.
| public void | reset()Resets the MessageDigest to the initial state for further use.
num[0] = 0;
for (int i = 0; i < 16; i++) {
data[i] = (byte) 0;
cksm[i] = 0;
state[i] = 0;
}
| public void | update(byte[] inBuf, int inOff, int inLen)Accumulates a hash of the input data. Continues an MD2
message-digest operation, processing another message
block, and updating the internal context.
if (inLen == 0) {
return;
}
// check parameters to prevent VM from crashing
int test = inBuf[inOff] + inBuf[inLen - 1] + inBuf[inOff + inLen - 1];
nativeUpdate(inBuf, inOff, inLen, state, num, cksm, data);
|
|