MessageDigest Class

Definition

This MessageDigest class provides applications the functionality of a message digest algorithm, such as SHA-1 or SHA-256.

[Android.Runtime.Register("java/security/MessageDigest", DoNotGenerateAcw=true)]
public abstract class MessageDigest : Java.Security.MessageDigestSpi
[<Android.Runtime.Register("java/security/MessageDigest", DoNotGenerateAcw=true)>]
type MessageDigest = class
    inherit MessageDigestSpi
Inheritance
Attributes

Remarks

This MessageDigest class provides applications the functionality of a message digest algorithm, such as SHA-1 or SHA-256. Message digests are secure one-way hash functions that take arbitrary-sized data and output a fixed-length hash value.

A MessageDigest object starts out initialized. The data is processed through it using the #update(byte) update methods. At any point #reset() reset can be called to reset the digest. Once all the data to be updated has been updated, one of the #digest() digest methods should be called to complete the hash computation.

The digest method can be called once for a given number of updates. After digest has been called, the MessageDigest object is reset to its initialized state.

Implementations are free to implement the Cloneable interface. Client applications can test cloneability by attempting cloning and catching the CloneNotSupportedException:

{@code
            MessageDigest md = MessageDigest.getInstance("SHA-256");

            try {
                md.update(toChapter1);
                MessageDigest tc1 = md.clone();
                byte[] toChapter1Digest = tc1.digest();
                md.update(toChapter2);
                ...etc.
            } catch (CloneNotSupportedException cnse) {
                throw new DigestException("couldn't make digest of partial content");
            }
            }

Note that if a given implementation is not cloneable, it is still possible to compute intermediate digests by instantiating several instances, if the number of digests is known in advance.

Note that this class is abstract and extends from MessageDigestSpi for historical reasons. Application developers should only take notice of the methods defined in this MessageDigest class; all the methods in the superclass are intended for cryptographic service providers who wish to supply their own implementations of message digest algorithms.

Android provides the following MessageDigest algorithms: <table> <thead> <tr> <th>Algorithm</th> <th>Supported API Levels</th> </tr> </thead> <tbody> <tr> <td>MD5</td> <td>1+</td> </tr> <tr> <td>SHA-1</td> <td>1+</td> </tr> <tr> <td>SHA-224</td> <td>1-8,22+</td> </tr> <tr> <td>SHA-256</td> <td>1+</td> </tr> <tr> <td>SHA-384</td> <td>1+</td> </tr> <tr> <td>SHA-512</td> <td>1+</td> </tr> </tbody> </table>

These algorithms are described in the MessageDigest section of the Java Cryptography Architecture Standard Algorithm Name Documentation.

Added in 1.1.

Java documentation for java.security.MessageDigest.

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

MessageDigest(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

MessageDigest(String)

Creates a message digest with the specified algorithm name.

Properties

Algorithm

Returns a string that identifies the algorithm, independent of implementation details.

Class

Returns the runtime class of this Object.

(Inherited from Object)
DigestLength

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.

Handle

The handle to the underlying Android instance.

(Inherited from Object)
JniIdentityHashCode (Inherited from Object)
JniPeerMembers
PeerReference (Inherited from Object)
Provider

Returns the provider of this message digest object.

ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

Methods

Clone()

Returns a clone if the implementation is cloneable.

(Inherited from MessageDigestSpi)
Digest()

Completes the hash computation by performing final operations such as padding.

Digest(Byte[])

Performs a final update on the digest using the specified array of bytes, then completes the digest computation.

Digest(Byte[], Int32, Int32)

Completes the hash computation by performing final operations such as padding.

Dispose() (Inherited from Object)
Dispose(Boolean) (Inherited from Object)
EngineDigest()

Completes the hash computation by performing final operations such as padding.

(Inherited from MessageDigestSpi)
EngineDigest(Byte[], Int32, Int32)

Completes the hash computation by performing final operations such as padding.

(Inherited from MessageDigestSpi)
EngineGetDigestLength()

Returns the digest length in bytes.

(Inherited from MessageDigestSpi)
EngineReset()

Resets the digest for further use.

(Inherited from MessageDigestSpi)
EngineUpdate(Byte[], Int32, Int32)

Updates the digest using the specified array of bytes, starting at the specified offset.

(Inherited from MessageDigestSpi)
EngineUpdate(ByteBuffer)

Update the digest using the specified ByteBuffer.

(Inherited from MessageDigestSpi)
EngineUpdate(SByte)

Updates the digest using the specified byte.

(Inherited from MessageDigestSpi)
Equals(Object)

Indicates whether some other object is "equal to" this one.

(Inherited from Object)
GetHashCode()

Returns a hash code value for the object.

(Inherited from Object)
GetInstance(String)

Returns a MessageDigest object that implements the specified digest algorithm.

GetInstance(String, Provider)

Returns a MessageDigest object that implements the specified digest algorithm.

GetInstance(String, String)

Returns a MessageDigest object that implements the specified digest algorithm.

IsEqual(Byte[], Byte[])

Compares two digests for equality.

JavaFinalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

(Inherited from Object)
Notify()

Wakes up a single thread that is waiting on this object's monitor.

(Inherited from Object)
NotifyAll()

Wakes up all threads that are waiting on this object's monitor.

(Inherited from Object)
Reset()

Resets the digest for further use.

SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
ToArray<T>() (Inherited from Object)
ToString()

Returns a string representation of the object.

(Inherited from Object)
UnregisterFromRuntime() (Inherited from Object)
Update(Byte[])

Updates the digest using the specified array of bytes.

Update(Byte[], Int32, Int32)

Updates the digest using the specified array of bytes, starting at the specified offset.

Update(ByteBuffer)

Update the digest using the specified ByteBuffer.

Update(SByte)

Updates the digest using the specified byte.

Wait()

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>.

(Inherited from Object)
Wait(Int64)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)
Wait(Int64, Int32)

Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed.

(Inherited from Object)

Explicit Interface Implementations

IJavaPeerable.Disposed() (Inherited from Object)
IJavaPeerable.DisposeUnlessReferenced() (Inherited from Object)
IJavaPeerable.Finalized() (Inherited from Object)
IJavaPeerable.JniManagedPeerState (Inherited from Object)
IJavaPeerable.SetJniIdentityHashCode(Int32) (Inherited from Object)
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) (Inherited from Object)
IJavaPeerable.SetPeerReference(JniObjectReference) (Inherited from Object)

Extension Methods

JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable)

Applies to