Methods Summary |
---|
public java.lang.Object | clone()Returns a clone if the implementation is cloneable.
if (this instanceof Cloneable) {
return super.clone();
} else {
throw new CloneNotSupportedException();
}
|
public byte[] | digest()Completes the hash computation by performing final operations
such as padding. The digest is reset after this call is made.
/* Resetting is the responsibility of implementors. */
byte[] result = engineDigest();
state = INITIAL;
return result;
|
public int | digest(byte[] buf, int offset, int len)Completes the hash computation by performing final operations
such as padding. The digest is reset after this call is made.
if (buf == null) {
throw new IllegalArgumentException("No output buffer given");
}
if (buf.length - offset < len) {
throw new IllegalArgumentException
("Output buffer too small for specified offset and length");
}
int numBytes = engineDigest(buf, offset, len);
state = INITIAL;
return numBytes;
|
public byte[] | digest(byte[] input)Performs a final update on the digest using the specified array
of bytes, then completes the digest computation. That is, this
method first calls {@link #update(byte[]) update(input)},
passing the input array to the update method,
then calls {@link #digest() digest()}.
update(input);
return digest();
|
public final java.lang.String | getAlgorithm()Returns a string that identifies the algorithm, independent of
implementation details. The name should be a standard
Java Security name (such as "SHA", "MD5", and so on).
See Appendix A in the
Java Cryptography Architecture API Specification & Reference
for information about standard algorithm names.
return this.algorithm;
|
public final int | getDigestLength()Returns the length of the digest in bytes, or 0 if this operation is
not supported by the provider and the implementation is not cloneable.
int digestLen = engineGetDigestLength();
if (digestLen == 0) {
try {
MessageDigest md = (MessageDigest)clone();
byte[] digest = md.digest();
return digest.length;
} catch (CloneNotSupportedException e) {
return digestLen;
}
}
return digestLen;
|
public static java.security.MessageDigest | getInstance(java.lang.String algorithm)Returns a MessageDigest object that implements the specified digest
algorithm.
This method traverses the list of registered security Providers,
starting with the most preferred Provider.
A new MessageDigest object encapsulating the
MessageDigestSpi implementation from the first
Provider that supports the specified algorithm is returned.
Note that the list of registered providers may be retrieved via
the {@link Security#getProviders() Security.getProviders()} method.
try {
Object[] objs = Security.getImpl(algorithm, "MessageDigest",
(String)null);
if (objs[0] instanceof MessageDigest) {
MessageDigest md = (MessageDigest)objs[0];
md.provider = (Provider)objs[1];
return md;
} else {
MessageDigest delegate =
new Delegate((MessageDigestSpi)objs[0], algorithm);
delegate.provider = (Provider)objs[1];
return delegate;
}
} catch(NoSuchProviderException e) {
throw new NoSuchAlgorithmException(algorithm + " not found");
}
|
public static java.security.MessageDigest | getInstance(java.lang.String algorithm, java.lang.String provider)Returns a MessageDigest object that implements the specified digest
algorithm.
A new MessageDigest object encapsulating the
MessageDigestSpi implementation from the specified provider
is returned. The specified provider must be registered
in the security provider list.
Note that the list of registered providers may be retrieved via
the {@link Security#getProviders() Security.getProviders()} method.
if (provider == null || provider.length() == 0)
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
if (objs[0] instanceof MessageDigest) {
MessageDigest md = (MessageDigest)objs[0];
md.provider = (Provider)objs[1];
return md;
} else {
MessageDigest delegate =
new Delegate((MessageDigestSpi)objs[0], algorithm);
delegate.provider = (Provider)objs[1];
return delegate;
}
|
public static java.security.MessageDigest | getInstance(java.lang.String algorithm, java.security.Provider provider)Returns a MessageDigest object that implements the specified digest
algorithm.
A new MessageDigest object encapsulating the
MessageDigestSpi implementation from the specified Provider
object is returned. Note that the specified Provider object
does not have to be registered in the provider list.
if (provider == null)
throw new IllegalArgumentException("missing provider");
Object[] objs = Security.getImpl(algorithm, "MessageDigest", provider);
if (objs[0] instanceof MessageDigest) {
MessageDigest md = (MessageDigest)objs[0];
md.provider = (Provider)objs[1];
return md;
} else {
MessageDigest delegate =
new Delegate((MessageDigestSpi)objs[0], algorithm);
delegate.provider = (Provider)objs[1];
return delegate;
}
|
public final java.security.Provider | getProvider()Returns the provider of this message digest object.
return this.provider;
|
public static boolean | isEqual(byte[] digesta, byte[] digestb)Compares two digests for equality. Does a simple byte compare.
if (digesta.length != digestb.length)
return false;
for (int i = 0; i < digesta.length; i++) {
if (digesta[i] != digestb[i]) {
return false;
}
}
return true;
|
public void | reset()Resets the digest for further use.
engineReset();
state = INITIAL;
|
public java.lang.String | toString()Returns a string representation of this message digest object.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintStream p = new PrintStream(baos);
p.print(algorithm+" Message Digest from "+provider.getName()+", ");
switch (state) {
case INITIAL:
p.print("<initialized>");
break;
case IN_PROGRESS:
p.print("<in progress>");
break;
}
p.println();
return (baos.toString());
|
public void | update(byte input)Updates the digest using the specified byte.
engineUpdate(input);
state = IN_PROGRESS;
|
public void | update(byte[] input, int offset, int len)Updates the digest using the specified array of bytes, starting
at the specified offset.
if (input == null) {
throw new IllegalArgumentException("No input buffer given");
}
if (input.length - offset < len) {
throw new IllegalArgumentException("Input buffer too short");
}
engineUpdate(input, offset, len);
state = IN_PROGRESS;
|
public void | update(byte[] input)Updates the digest using the specified array of bytes.
engineUpdate(input, 0, input.length);
state = IN_PROGRESS;
|
public final void | update(java.nio.ByteBuffer input)Update the digest using the specified ByteBuffer. The digest is
updated using the input.remaining() bytes starting
at input.position() .
Upon return, the buffer's position will be equal to its limit;
its limit will not have changed.
if (input == null) {
throw new NullPointerException();
}
engineUpdate(input);
state = IN_PROGRESS;
|