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)Generates a MessageDigest object that implements the specified digest
algorithm. If the default provider package
provides an implementation of the requested digest algorithm,
an instance of MessageDigest containing that implementation is returned.
If the algorithm is not available in the default
package, other packages are searched.
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)Generates a MessageDigest object implementing the specified
algorithm, as supplied from the specified provider, if such an
algorithm is available from the provider.
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)Generates a MessageDigest object implementing the specified
algorithm, as supplied from the specified provider, if such an
algorithm is available from the provider. Note: the
provider doesn't have to be registered.
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;
|