public abstract class MessageDigest extends MessageDigestSpi
MessageDigestSpi| Modifier | Constructor and Description |
|---|---|
protected |
MessageDigest(String algorithm)
Constructs a new instance of
MessageDigest representing the
specified algorithm. |
| Modifier and Type | Method and Description |
|---|---|
Object |
clone()
Returns a clone of this instance if cloning is supported.
|
byte[] |
digest()
Computes the final digest of the stored data.
|
byte[] |
digest(byte[] input)
Computes a final update using the input array of bytes, then computes a
final digest and returns it.
|
int |
digest(byte[] buf,
int offset,
int len)
Computes the final digest of the stored bytes and returns the result.
|
String |
getAlgorithm()
Returns the name of message digest algorithm.
|
int |
getDigestLength()
Returns the length of the message digest.
|
static MessageDigest |
getInstance(String algorithm)
Returns a new instance of
MessageDigest representing the
specified algorithm. |
static MessageDigest |
getInstance(String algorithm,
Provider provider)
Returns a new instance of
MessageDigest representing the
specified algorithm from a designated Provider. |
static MessageDigest |
getInstance(String algorithm,
String provider)
Returns a new instance of
MessageDigest representing the
specified algorithm from a named provider. |
Provider |
getProvider()
Returns the
Provider of this instance. |
static boolean |
isEqual(byte[] digesta,
byte[] digestb)
Does a simple byte comparison of the two digests.
|
void |
reset()
Resets this instance.
|
String |
toString()
Returns a string representation of this instance.
|
void |
update(byte input)
Updates the digest with the byte.
|
void |
update(byte[] input)
Updates the digest with the bytes of an array.
|
void |
update(byte[] input,
int offset,
int len)
Updates the digest with the bytes from the array starting from the
specified offset and using the specified length of bytes.
|
void |
update(ByteBuffer input)
Updates the digest with the remaining bytes of a buffer.
|
engineDigest, engineDigest, engineGetDigestLength, engineReset, engineUpdate, engineUpdate, engineUpdateprotected MessageDigest(String algorithm)
MessageDigest representing the
specified algorithm.algorithm - the name of the digest algorithm to use.public static MessageDigest getInstance(String algorithm) throws NoSuchAlgorithmException
MessageDigest representing the
specified algorithm.algorithm - the name of the digest algorithm to use.NoSuchAlgorithmException - if the algorithm is not implemented by any
provider.IllegalArgumentException - if algorithm is
null or is an empty string.public static MessageDigest getInstance(String algorithm, String provider) throws NoSuchAlgorithmException, NoSuchProviderException
MessageDigest representing the
specified algorithm from a named provider.algorithm - the name of the digest algorithm to use.provider - the name of the provider to use.NoSuchAlgorithmException - if the algorithm is not implemented by the
named provider.NoSuchProviderException - if the named provider was not found.IllegalArgumentException - if either algorithm or
provider is null or empty.public static MessageDigest getInstance(String algorithm, Provider provider) throws NoSuchAlgorithmException
MessageDigest representing the
specified algorithm from a designated Provider.algorithm - the name of the digest algorithm to use.provider - the Provider to use.NoSuchAlgorithmException - if the algorithm is not implemented by
Provider.IllegalArgumentException - if either algorithm or
provider is null, or if
algorithm is an empty string.Providerpublic final Provider getProvider()
Provider of this instance.Provider of this instance.public void update(byte input)
input - byte to update the digest with.public void update(byte[] input, int offset, int len)
input - bytes to update the digest with.offset - the offset to start at.len - length of the data to update with.public void update(byte[] input)
input - bytes to update the digest with.public final void update(ByteBuffer input)
input - The input byte buffer.public byte[] digest()
public int digest(byte[] buf, int offset, int len) throws DigestException
buf - an array of bytes to store the result in.offset - an offset to start storing the result at.len - the length of the buffer.DigestExceptionpublic byte[] digest(byte[] input)
update(byte[]) and then
digest(byte[]).input - an array of bytes to perform final update with.public String toString()
toString in class ObjectObject.getClass(),
Object.hashCode(),
Class.getName(),
Integer.toHexString(int)public static boolean isEqual(byte[] digesta, byte[] digestb)
digesta - first digest to compare.digestb - second digest to compare.true if both are equal, false
otherwise.public void reset()
public final String getAlgorithm()
public final int getDigestLength()
public Object clone() throws CloneNotSupportedException
CloneNotSupportedException is thrown. Cloning depends on
whether the subclass MessageDigestSpi implements Cloneable
which contains the actual implementation of the appropriate algorithm.clone in class MessageDigestSpiCloneNotSupportedException - the implementation does not support cloning.Cloneable