This documentation is archived and is not being maintained.

HashAlgorithm Class

Represents the base class from which all implementations of cryptographic hash algorithms must derive.

For a list of all members of this type, see HashAlgorithm Members.

      Derived classes

[Visual Basic]
MustInherit Public Class HashAlgorithm
   Implements ICryptoTransform, IDisposable
public abstract class HashAlgorithm : ICryptoTransform, IDisposable
public __gc __abstract class HashAlgorithm : public
   ICryptoTransform, IDisposable
public abstract class HashAlgorithm implements ICryptoTransform,

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Hash functions are fundamental to modern cryptography. These functions map binary strings of an arbitrary length to small binary strings of a fixed length, known as hash values. A cryptographic hash function has the property that it is computationally infeasible to find two distinct inputs that hash to the same value. Hash functions are commonly used with digital signatures and for data integrity.

The hash is used as a unique value of fixed size representing a large amount of data. Hashes of two sets of data should match if the corresponding data also matches. Small changes to the data result in large unpredictable changes in the hash.

Notes to Inheritors:  When overriding this class, you must provide implementations of HashCore and HashFinal.


[Visual Basic, C#, C++] The following example computes the SHA1CryptoServiceProvider hash for an array. This example assumes that there is a predefined byte array dataArray[]. SHA1CryptoServiceProvider is a derived class of HashAlgorithm.

[Visual Basic] 
Dim sha As New SHA1CryptoServiceProvider()
Dim result As Byte() = sha.ComputeHash(dataArray)

HashAlgorithm sha = new SHA1CryptoServiceProvider();
byte[] result = sha.ComputeHash(dataArray);

HashAlgorithm* sha = new SHA1CryptoServiceProvider();
Byte result[] = sha->ComputeHash(dataArray);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Security.Cryptography

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: Mscorlib (in Mscorlib.dll)

See Also

HashAlgorithm Members | System.Security.Cryptography Namespace | Cryptographic Services