public class Md2
extends java.security.MessageDigest
implements java.lang.Cloneable, java.io.Serializable
by Ron Rivest's MD2 algorithm is described by Burt Kaliski in RFC 1319 (and previously in RFC 1115). It is a secure hash function that takes input of arbitrary length and produces an output of exactly 16 bytes (128 bit).
It is designed for 8 bit machines and therefore does not deliver optimum performance on todays processors with a wordsize of 32 and more bits. Additionally, some weaknesses have been found in the compression function employed by MD2, although the algorithm can still be considered secure because of a checksum that is appended to the data. Nevertheless we recommend using MD5 or even better SHA-1 both for speed and security reasons. Basically MD2 is implemented only to allow certain certificates from RSA Inc. and Verisign to be verified.
An excerpt from the original RFC1319 follows:
This document describes the MD2 message-digest algorithm. The algorithm takes as input a message of arbitrary length and produces as output a 128-bit "fingerprint" or "message digest" of the input. It is conjectured that it is computationally infeasible to produce two messages having the same message digest, or to produce any message having a given prespecified target message digest. The MD2 algorithm is intended for digital signature applications, where a large file must be "compressed" in a secure manner before being signed with a private (secret) key under a public-key cryptosystem such as RSA.
This class extends the java.security.MessageDigest class
and applications should use one of the getInstance methods
presented there to create a MessageDigest-MD2 object.
Generally, an application wishing to compute the message digest of some
data has to perform three steps:
getInstance method, e.g.:
MessageDigest md2 = MessageDigest.getInstance("MD2", "IAIK");
update methods,
e.g:
md2.update(m1);
md2.update(m2);
...
digest methods:
byte[] hash_value = md2.digest();
There are several ways for combining update and
digest methods for computing a message digest. Since
this class implements the Cloneable interface,
MD2 MessageDigest objects may be used for compute intermediate
hashes through cloning (see
http://java.sun.com/products/JDK/1.1/docs/guide/security/CryptoSpec.html).
When the hash value successfully has been computed, the MD2 MessageDigest object automatically resets for being able to be supplied with new data to be hashed.
The MD2 algorithm may be combined with a public-key algorithm (e.g. RSA) to be used as digital signature algorithm (see iaik.security.rsa.Md2RSASignature).
Md2RSASignature,
SHA1,
MD5,
Serialized Form| Constructor and Description |
|---|
Md2()
The constructor; creates a new instance of the MD2 message digest
algorithm.
|
| Modifier and Type | Method and Description |
|---|---|
java.lang.Object |
clone()
Creates and returns a copy of this object.
|
void |
destroyCriticalData()
Clears any sensitive data held internally by this algorithm.
|
byte[] |
engineDigest()
Completes the hash computation by performing final operations such as
padding.
|
void |
engineReset()
Resets the digest for further use.
|
void |
engineUpdate(byte input)
Updates the digest using the specified byte.
|
void |
engineUpdate(byte[] input,
int offset,
int len)
Updates the digest using the specified array of bytes, starting at the
specified offset.
|
protected void |
finalize()
The finalizer.
|
digest, digest, digest, getAlgorithm, getDigestLength, getInstance, getInstance, getInstance, getProvider, isEqual, reset, toString, update, update, update, updatepublic Md2()
Applications should not use this constructor, instead the message digest
algorithm should be requested from the appropriate JCA/JCE cryptographic
service provider as follows:
MessageDigest.getInstance("MD2", "IAIK").
public void engineUpdate(byte[] input,
int offset,
int len)
engineUpdate in class java.security.MessageDigestSpiinput - [FIPS 140-2 data input] the array of bytes to use for the
update.offset - [FIPS 140-2 data input] the offset to start from in the array
of bytes.len - [FIPS 140-2 data input] the number of bytes to use, starting
at offset.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic void engineUpdate(byte input)
engineUpdate in class java.security.MessageDigestSpiinput - [FIPS 140-2 data input] the byte to use for the update.Fips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic void engineReset()
engineReset in class java.security.MessageDigestSpiFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic byte[] engineDigest()
engineDigest has been called, the engine
should be reset (see engineReset). Resetting is
the responsibility of the engine implementor.
engineDigest in class java.security.MessageDigestSpiFips140ErrorStateException - [FIPS 140-2 status output] thrown if the Toolkit is not
allowed to perform cryptographic operationspublic java.lang.Object clone()
clone in class java.security.MessageDigestpublic void destroyCriticalData()
protected void finalize()
finalize in class java.lang.Object