|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.novell.java.security.MessageDigestSpi | +--com.novell.java.security.MessageDigest
Provides applications with the functionality of a message digest algorithm, such as MD5 or SHA. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.
A MessageDigest object starts out initialized. The data is processed through it using the update() methods. At any point the reset() method can be called to reset the digest. Once all the data has been updated, one of the digest() methods should be called to complete the hash computation. The digest() method can be called once for a given number of updates. After digest() has been called, the MessageDigest object is reset to its initialized state.
Implementations of the MessageDigest class can be used by implementing the Cloneable interface. Such an implementation will let client applications test cloneability using instanceof Cloneable before cloning. Following is such an example:
MessageDigest md = MessageDigest.getInstance("SHA"); if (md instanceof Cloneable) { md.update(toChapter1); MessageDigest tc1 = md.clone(); byte[] toChapter1Digest = tc1.digest; md.update(toChapter2); ...etc. } else { throw new DigestException("couldn't make digest of partial content"); }
If a given implementation is not cloneable, but the number of digests is known in advance, it is still possible to compute intermediate digests by instantiating several instances.
The MessageDigest class is abstract and extends from the MessageDigestSpi class for historical reasons. Application developers should only take notice of the methods defined in this MessageDigest class, and ignore all the methods in the superclass.
DigestInputStream
,
DigestOutputStream
,
MessageDigestSpi
Method Summary | |
java.lang.Object |
clone()
Creates a new message digest object of the same class as this message digest object. |
byte[] |
digest()
Completes the hash computation by performing final operations such as padding. |
byte[] |
digest(byte[] input)
Performs a final update and digest computation on the digest using the specified array of bytes. |
int |
digest(byte[] buf,
int offset,
int len)
Completes the hash computation by performing final operations such as padding. |
java.lang.String |
getAlgorithm()
Returns a string that identifies the algorithm, independent of implementation details. |
int |
getDigestLength()
Returns the length of the digest in bytes. |
static MessageDigest |
getInstance(java.lang.String algorithm)
Generates a MessageDigest object that implements the specified digest algorithm. |
static MessageDigest |
getInstance(java.lang.String algorithm,
java.lang.String provider)
Generates a MessageDigest object implementing the specified algorithm as supplied from the specified provider. |
Provider |
getProvider()
Returns the Provider of this message digest object. |
static boolean |
isEqual(byte[] digesta,
byte[] digestb)
Compares two digests for equality using a simple byte compare. |
void |
reset()
Resets the digest for further use. |
java.lang.String |
toString()
Returns a string representation of this message digest object. |
void |
update(byte input)
Updates the message digest using the specified byte. |
void |
update(byte[] input)
Updates the message digest using the specified array of bytes. |
void |
update(byte[] input,
int offset,
int len)
Updates the message digest using the specified array of bytes, starting at the specified offset. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Method Detail |
public static MessageDigest getInstance(java.lang.String algorithm) throws NoSuchAlgorithmException
algorithm
- The name of the algorithm requested.public static MessageDigest getInstance(java.lang.String algorithm, java.lang.String provider) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm
- The name of the algorithm requested.provider
- The name of the provider.Provider
public final Provider getProvider()
public void update(byte input)
input
- The byte with which to update the digest.public void update(byte[] input, int offset, int len)
input
- The array of bytes.offset
- The offset in the array of bytes from which to start.len
- The number of bytes to use, starting at the offset.public void update(byte[] input)
input
- The array of bytes.public byte[] digest()
public int digest(byte[] buf, int offset, int len) throws DigestException
buf
- The output buffer for the computed digest.offset
- The offset into the output buffer at which to
begin storing the digest.len
- The number of bytes within the output buffer (buf)
allotted for the digest.public byte[] digest(byte[] input)
input
- The input to be updated before the digest is
completed.public java.lang.String toString()
public static boolean isEqual(byte[] digesta, byte[] digestb)
digesta
- One of the digests to compare.digestb
- The other digest to compare.public void reset()
public final java.lang.String getAlgorithm()
public final int getDigestLength()
public java.lang.Object clone() throws java.lang.CloneNotSupportedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |