public abstract class

MessageDigest

extends MessageDigestSpi
java.lang.Object
   ↳ java.security.MessageDigestSpi
     ↳ java.security.MessageDigest

Class Overview

MessageDigest is an engine class which is capable of generating one way hash values for arbitrary input, utilizing the algorithm it was initialized with.

See Also

Summary

Protected Constructors
MessageDigest(String algorithm)
Constructs a new instance of MessageDigest with the name of the algorithm to use.
Public Methods
Object clone()
Creates and returns a copy of this Object.
byte[] digest()
Computes and returns the final hash value for this MessageDigest.
byte[] digest(byte[] input)
Performs the final update and then computes and returns the final hash value for this MessageDigest.
int digest(byte[] buf, int offset, int len)
Computes and stores the final hash value for this MessageDigest.
final String getAlgorithm()
Returns the name of the algorithm of this MessageDigest.
final int getDigestLength()
Returns the engine digest length in bytes.
static MessageDigest getInstance(String algorithm, String provider)
Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.
static MessageDigest getInstance(String algorithm)
Returns a new instance of MessageDigest that utilizes the specified algorithm.
static MessageDigest getInstance(String algorithm, Provider provider)
Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.
final Provider getProvider()
Returns the provider associated with this MessageDigest.
static boolean isEqual(byte[] digesta, byte[] digestb)
Indicates whether to digest are equal by performing a simply byte-per-byte compare of the two digests.
void reset()
Puts this MessageDigest back in an initial state, such that it is ready to compute a one way hash value.
String toString()
Returns a string containing a concise, human-readable description of this MessageDigest including the name of its algorithm.
void update(byte[] input)
Updates this MessageDigest using the given byte[].
void update(byte arg0)
Updates this MessageDigest using the given byte.
void update(byte[] input, int offset, int len)
Updates this MessageDigest using the given byte[].
final void update(ByteBuffer input)
Updates this MessageDigest using the given input.
[Expand]
Inherited Methods
From class java.security.MessageDigestSpi
From class java.lang.Object

Protected Constructors

protected MessageDigest (String algorithm)

Since: API Level 1

Constructs a new instance of MessageDigest with the name of the algorithm to use.

Parameters
algorithm the name of algorithm to use

Public Methods

public Object clone ()

Since: API Level 1

Creates and returns a copy of this Object. The default implementation returns a so-called "shallow" copy: It creates a new instance of the same class and then copies the field values (including object references) from this instance to the new instance. A "deep" copy, in contrast, would also recursively clone nested objects. A subclass that needs to implement this kind of cloning should call super.clone() to create the new instance and then create deep copies of the nested, mutable objects.

Returns
  • a copy of this object.

public byte[] digest ()

Since: API Level 1

Computes and returns the final hash value for this MessageDigest. After the digest is computed the receiver is reset.

Returns
  • the computed one way hash value
See Also

public byte[] digest (byte[] input)

Since: API Level 1

Performs the final update and then computes and returns the final hash value for this MessageDigest. After the digest is computed the receiver is reset.

Parameters
input the byte array
Returns
  • the computed one way hash value
See Also

public int digest (byte[] buf, int offset, int len)

Since: API Level 1

Computes and stores the final hash value for this MessageDigest. After the digest is computed the receiver is reset.

Parameters
buf the buffer to store the result
offset the index of the first byte in buf to store
len the number of bytes allocated for the digest
Returns
  • the number of bytes written to buf
Throws
DigestException if an error occures
IllegalArgumentException if offset or len are not valid in respect to buf
See Also

public final String getAlgorithm ()

Since: API Level 1

Returns the name of the algorithm of this MessageDigest.

Returns
  • the name of the algorithm of this MessageDigest

public final int getDigestLength ()

Since: API Level 1

Returns the engine digest length in bytes. If the implementation does not implement this function or is not an instance of Cloneable, 0 is returned.

Returns
  • the digest length in bytes, or 0

public static MessageDigest getInstance (String algorithm, String provider)

Since: API Level 1

Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.

Parameters
algorithm the name of the algorithm to use
provider the name of the provider
Returns
  • a new instance of MessageDigest that utilizes the specified algorithm from the specified provider
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NoSuchProviderException if the specified provider is not available
NullPointerException if algorithm is null

public static MessageDigest getInstance (String algorithm)

Since: API Level 1

Returns a new instance of MessageDigest that utilizes the specified algorithm.

Parameters
algorithm the name of the algorithm to use
Returns
  • a new instance of MessageDigest that utilizes the specified algorithm
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NullPointerException if algorithm is null

public static MessageDigest getInstance (String algorithm, Provider provider)

Since: API Level 1

Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.

Parameters
algorithm the name of the algorithm to use
provider the provider
Returns
  • a new instance of MessageDigest that utilizes the specified algorithm from the specified provider
Throws
NoSuchAlgorithmException if the specified algorithm is not available
NullPointerException if algorithm is null

public final Provider getProvider ()

Since: API Level 1

Returns the provider associated with this MessageDigest.

Returns
  • the provider associated with this MessageDigest

public static boolean isEqual (byte[] digesta, byte[] digestb)

Since: API Level 1

Indicates whether to digest are equal by performing a simply byte-per-byte compare of the two digests.

Parameters
digesta the first digest to be compared
digestb the second digest to be compared
Returns
  • true if the two hashes are equal, false otherwise

public void reset ()

Since: API Level 1

Puts this MessageDigest back in an initial state, such that it is ready to compute a one way hash value.

public String toString ()

Since: API Level 1

Returns a string containing a concise, human-readable description of this MessageDigest including the name of its algorithm.

Returns
  • a printable representation for this MessageDigest

public void update (byte[] input)

Since: API Level 1

Updates this MessageDigest using the given byte[].

Parameters
input the byte array
Throws
NullPointerException if input is null

public void update (byte arg0)

Since: API Level 1

Updates this MessageDigest using the given byte.

Parameters
arg0 the byte to update this MessageDigest with
See Also

public void update (byte[] input, int offset, int len)

Since: API Level 1

Updates this MessageDigest using the given byte[].

Parameters
input the byte array
offset the index of the first byte in input to update from
len the number of bytes in input to update from
Throws
IllegalArgumentException if offset or len are not valid in respect to input

public final void update (ByteBuffer input)

Since: API Level 1

Updates this MessageDigest using the given input.

Parameters
input the ByteBuffer