Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |
java.lang.Object | +----java.security.MessageDigestSpi | +----java.security.MessageDigest
A MessageDigest object starts out initialized. The data is processed through it using the update methods. At any point reset can be called to reset the digest. Once all the data to be updated 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 are free to implement the Cloneable interface.
Client applications can test cloneability
using instanceof Cloneable
before attempting cloning:
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"); }
Note that if a given implementation is not cloneable, it is still possible to compute intermediate digests by instantiating several instances, if the number of digests is known in advance.
Note that this class is abstract and extends from
MessageDigestSpi
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.
Constructor Summary | |
MessageDigest(String algorithm)
|
Method Summary | |
Object | clone()
|
byte[] | digest()
|
int | digest(byte[] buf,
int offset,
int len)
|
byte[] | digest(byte[] input)
|
String | getAlgorithm()
|
int | getDigestLength()
|
static MessageDigest | getInstance(String algorithm)
|
static MessageDigest | getInstance(String algorithm,
String provider)
|
Provider | getProvider()
|
static boolean | isEqual(byte[] digesta,
byte[] digestb)
|
void | reset()
|
String | toString()
|
void | update(byte input)
|
void | update(byte[] input,
int offset,
int len)
|
void | update(byte[] input)
|
Methods inherited from class java.security.MessageDigestSpi |
clone, engineDigest, engineDigest, engineGetDigestLength, engineReset, engineUpdate, engineUpdate |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
protected MessageDigest(String algorithm)
algorithm
- the standard name of the digest algorithm.
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.
Method Detail |
public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException
algorithm
- the name of the algorithm requested.
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.
public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
algorithm
- the name of the algorithm requested.
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.
provider
- the name of the 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 to start from in the array of bytes.
len
- the number of bytes to use, starting at
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
- output buffer for the computed digest
offset
- offset into the output buffer to begin storing the digest
len
- number of bytes within buf allotted for the digest
public byte[] digest(byte[] input)
input
- the input to be updated before the digest is
completed.
public 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 String getAlgorithm()
public final int getDigestLength()
public Object clone() throws CloneNotSupportedException
Cloneable
.Contents | Package | Class | Tree | Deprecated | Index | Help | Java 1.2 Beta 3 | ||
PREV | NEXT | SHOW LISTS | HIDE LISTS |