Android Guides | Samples

Java.Security.MessageDigest Class

Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence.

See Also: MessageDigest

Syntax

[Android.Runtime.Register("java/security/MessageDigest", DoNotGenerateAcw=true)]
public abstract class MessageDigest : MessageDigestSpi

Remarks

Uses a one-way hash function to turn an arbitrary number of bytes into a fixed-length byte sequence. The original arbitrary-length sequence is the message, and the fixed-length byte sequence is the digest or message digest.

Sample Code

The basic pattern to digest an InputStream looks like this:

java Example

  MessageDigest digester = MessageDigest.getInstance("MD5");
  byte[] bytes = new byte[8192];
  int byteCount;
  while ((byteCount = in.read(bytes)) > 0) {
    digester.update(bytes, 0, byteCount);
  }
  byte[] digest = digester.digest();

That is, after creating or resetting a MessageDigest you should call MessageDigest.Update(Byte[],Int32,Int32) for each block of input data, and then call MessageDigest.Digest to get the final digest. Note that calling digest resets the MessageDigest. Advanced users who want partial digests should clone their MessageDigest before calling digest.

This class is not thread-safe.

See Also

[Android Documentation]

Requirements

Namespace: Java.Security
Assembly: Mono.Android (in Mono.Android.dll)
Assembly Versions: 0.0.0.0
Since: Added in API level 1

The members of Java.Security.MessageDigest are listed below.

See Also: MessageDigestSpi

Protected Constructors

Constructs a new instance of MessageDigest with the name of the algorithm to use.
A constructor used when creating managed representations of JNI objects; called by the runtime.

Public Properties

[read-only]
AlgorithmString. Returns the name of the algorithm of this MessageDigest.
[read-only]
DigestLengthInt32. Returns the engine digest length in bytes.
[read-only]
ProviderProvider. Returns the provider associated with this MessageDigest.

Protected Properties

[read-only]
override
ThresholdClassIntPtr. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.
[read-only]
override
ThresholdTypeType. This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Public Methods

Digest() : Byte[]
Computes and returns the final hash value for this MessageDigest.
Digest(Byte[]) : Byte[]
Performs the final update and then computes and returns the final hash value for this MessageDigest.
Digest(Byte[], Int32, Int32) : Int32
Computes and stores the final hash value for this MessageDigest.
static
GetInstance(String) : MessageDigest
Returns a new instance of MessageDigest that utilizes the specified algorithm.
static
GetInstance(String, Provider) : MessageDigest
Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.
static
GetInstance(String, String) : MessageDigest
Returns a new instance of MessageDigest that utilizes the specified algorithm from the specified provider.
static
IsEqual(Byte[], Byte[]) : Boolean
Indicates whether to digest are equal by performing a simply byte-per-byte compare of the two digests.
Reset()
Puts this MessageDigest back in an initial state, such that it is ready to compute a one way hash value.
Update(ByteBuffer)
Updates this MessageDigest using the given input.
Update(Byte[])
Updates this MessageDigest using the given byte[].
Update(SByte)
Updates this MessageDigest using the given byte.
Update(Byte[], Int32, Int32)
Updates this MessageDigest using the given byte[].