|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.me.security.MessageDigest
This is the main class for digest computation. A message digest is a one-way function that maps an arbitrarily long input to a fixed length output. It can be used in various ways including digital signatures or for MAC functions.
This class defines the API, forms the base class, and is a factory for MessageDigest implementations.
The API closely resembles the API used within the JCE in JDK 1.1 and later, that documentation may provide additional insight.
Note that MessageDigests should not be created directly via the constructor but preferably via
the getInstance(String)
method defined in this class.
For example:
MessageDigest digest = MessageDigest.getInstance("SHA1"); digest.update("MY TEST DATA".getBytes()); byte[] result = digest.digest();
Field Summary | |
protected byte[] |
buffer
Buffer, for use by implementations. |
protected long |
count
Count of the number of bytes processed so far, for use by implementations. |
protected int |
digestLength
|
protected static byte[] |
padding
Data suitable for padding of MD4 style digests. padding[0] == 0x80, all other bytes are zero. |
Constructor Summary | |
protected |
MessageDigest(int digestLength)
Constructor for implementations that do not which to use the buffering features of this class. |
protected |
MessageDigest(int digestLength,
int blockSize)
Constructor for implementations. |
Method Summary | |
abstract Object |
clone()
Returns a clone of this object. |
protected void |
compress(byte[] input,
int offset)
Compression function, to be implemented by subclasses. |
byte[] |
digest()
Computes the digest. |
byte[] |
digest(byte[] input)
Computes the digest. |
abstract int |
digest(byte[] output,
int offset)
Performs the final padding operations and computes the digest. |
String |
getAlgorithm()
Returns the name of the used digest algorithm. |
int |
getDigestLength()
Returns the length of the digestalgorithm output in bytes. |
abstract byte[][] |
getEncodedDigestInfo()
Returns the pregenerated ASN1 encoding of the DigestInfo structure for the corresponding digest algorithm, see . |
static MessageDigest |
getInstance(String algorithm)
Returns an instance of the MessageDigest with the given name. |
static void |
register(String name,
String clazz)
This method is used to register new (or self implemented) signature algorithms. For example: MessageDigest.register("SHA1", "iaik.me.security.md.SHA"); Once registered, the algorithm can be used via the getInstance(String) method. |
abstract void |
reset()
Resets the internal values of digest instance. |
void |
update(byte b)
Adds a byte to the digest data. |
void |
update(byte[] input)
Adds a byte array to the digest data. |
void |
update(byte[] input,
int offset,
int len)
Adds a byte array to the digest data. |
Methods inherited from class java.lang.Object |
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected static final byte[] padding
protected int digestLength
protected byte[] buffer
protected long count
Constructor Detail |
protected MessageDigest(int digestLength)
protected MessageDigest(int digestLength, int blockSize)
Method Detail |
public final String getAlgorithm()
public final int getDigestLength()
public void update(byte b)
b
- digest datapublic void update(byte[] input)
public void update(byte[] input, int offset, int len)
input
- the data to be hashed.offset
- startindexlen
- number of bytes to be hashed beginnig from the startindexprotected void compress(byte[] input, int offset)
public abstract int digest(byte[] output, int offset)
output
- the hash valueoffset
- starting index of the data to hashgetDigestLength()
public final byte[] digest(byte[] input)
update(byte[])
followed by digest()
.
This method needs to allocate a new byte array and hence may be
less efficient than the digest(byte[] , int )
method if used
frequently. The digest instance is automatically reset after the digest was computed.input
- the data to be hashedpublic final byte[] digest()
digest(byte[] , int )
method if used
frequently. The digest instance is automatically reset after the digest was computed.public abstract void reset()
public abstract Object clone()
clone
in class Object
public static MessageDigest getInstance(String algorithm) throws CryptoException
Algorithm names supported are MD2, MD5, SHA, SHA1, SHA-1 (alias for SHA), SHA-224, SHA-256
and the object ids registed in the ASN1
class.
algorithm
- the name of the digestalgorithmpublic abstract byte[][] getEncodedDigestInfo()
public static void register(String name, String clazz)
MessageDigest.register("SHA1", "iaik.me.security.md.SHA");Once registered, the algorithm can be used via the
getInstance(String)
method.name
- the name of the algorithmclazz
- the name of the class which implements the algorithm (with full package name)
|
This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |