HashAlgorithm 類別

定義

代表基底類別,密碼編譯雜湊演算法的所有實作必須從它衍生。Represents the base class from which all implementations of cryptographic hash algorithms must derive.

public ref class HashAlgorithm abstract : System::Security::Cryptography::ICryptoTransform
[System.Runtime.InteropServices.ComVisible(true)]
public abstract class HashAlgorithm : System.Security.Cryptography.ICryptoTransform
type HashAlgorithm = class
    interface IDisposable
    interface ICryptoTransform
Public MustInherit Class HashAlgorithm
Implements ICryptoTransform
繼承
HashAlgorithm
衍生
屬性
實作

範例

下列程式碼範例會計算SHA1CryptoServiceProvider陣列的雜湊。The following code example computes the SHA1CryptoServiceProvider hash for an array. 這個範例假設有一個預先定義的位元組陣列dataArray[]This example assumes that there is a predefined byte array dataArray[]. SHA1CryptoServiceProvider是的衍生類別HashAlgorithmSHA1CryptoServiceProvider is a derived class of HashAlgorithm.

HashAlgorithm^ sha = gcnew SHA1CryptoServiceProvider;
array<Byte>^ result = sha->ComputeHash( dataArray );
HashAlgorithm sha = new SHA1CryptoServiceProvider();
byte[] result = sha.ComputeHash(dataArray);
Dim sha As New SHA1CryptoServiceProvider()
Dim result As Byte() = sha.ComputeHash(dataArray)

備註

雜湊函數是新式密碼編譯的基礎。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.

由於 SHA1 的衝突問題,Microsoft 建議您使用以 SHA256 或更好的加密方式為基礎的安全性模型。Due to collision problems with SHA1, Microsoft recommends a security model based on SHA256 or better.

給繼承者的注意事項

當您繼承自HashAlgorithm類別時,您必須覆寫下列成員: HashCore(Byte[], Int32, Int32)和。 HashFinal()When you inherit from the HashAlgorithm class, you must override the following members: HashCore(Byte[], Int32, Int32) and HashFinal().

建構函式

HashAlgorithm()

初始化 HashAlgorithm 類別的新執行個體。Initializes a new instance of the HashAlgorithm class.

欄位

HashSizeValue

代表計算出來之雜湊碼的大小,以位元為單位。Represents the size, in bits, of the computed hash code.

HashValue

表示計算出來的雜湊碼的值。Represents the value of the computed hash code.

State

表示雜湊計算的狀態。Represents the state of the hash computation.

屬性

CanReuseTransform

取得值,表示目前的轉換是否可重複使用。Gets a value indicating whether the current transform can be reused.

CanTransformMultipleBlocks

在衍生類別中覆寫時,取得值以指出是否有多個區塊可被轉換。When overridden in a derived class, gets a value indicating whether multiple blocks can be transformed.

Hash

取得計算出來之雜湊碼的值。Gets the value of the computed hash code.

HashSize

取得計算出來的雜湊碼的大小,以位元為單位。Gets the size, in bits, of the computed hash code.

InputBlockSize

在衍生類別中覆寫時,取得輸入區塊的大小。When overridden in a derived class, gets the input block size.

OutputBlockSize

在衍生類別中覆寫時,取得輸出區塊的大小。When overridden in a derived class, gets the output block size.

方法

Clear()

釋放 HashAlgorithm 類別所使用的所有資源。Releases all resources used by the HashAlgorithm class.

ComputeHash(Byte[])

計算指定位元組陣列的雜湊值。Computes the hash value for the specified byte array.

ComputeHash(Byte[], Int32, Int32)

計算所指定位元組陣列中指定區域的雜湊值。Computes the hash value for the specified region of the specified byte array.

ComputeHash(Stream)

計算指定 Stream 物件的雜湊值。Computes the hash value for the specified Stream object.

Create()

建立雜湊演算法的預設實作執行個體。Creates an instance of the default implementation of a hash algorithm.

Create(String)

建立雜湊演算法之指定實作的執行個體。Creates an instance of the specified implementation of a hash algorithm.

Dispose()

釋放 HashAlgorithm 類別目前的執行個體所使用的全部資源。Releases all resources used by the current instance of the HashAlgorithm class.

Dispose(Boolean)

釋放 HashAlgorithm 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.

Equals(Object)

判斷指定的物件是否等於目前的物件。Determines whether the specified object is equal to the current object.

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。Serves as the default hash function.

(繼承來源 Object)
GetType()

取得目前執行個體的 TypeGets the Type of the current instance.

(繼承來源 Object)
HashCore(Byte[], Int32, Int32)

在衍生類別中覆寫時,將寫入物件的資料轉遞到用來計算雜湊的雜湊演算法。When overridden in a derived class, routes data written to the object into the hash algorithm for computing the hash.

HashCore(ReadOnlySpan<Byte>)
HashFinal()

在衍生類別中覆寫時,當密碼編譯資料流物件處理最後的資料後,會對雜湊計算做最後處理。When overridden in a derived class, finalizes the hash computation after the last data is processed by the cryptographic stream object.

Initialize()

初始化 HashAlgorithm 類別的實作。Initializes an implementation of the HashAlgorithm class.

MemberwiseClone()

建立目前 Object 的淺層複本 (Shallow Copy)。Creates a shallow copy of the current Object.

(繼承來源 Object)
ToString()

傳回代表目前物件的字串。Returns a string that represents the current object.

(繼承來源 Object)
TransformBlock(Byte[], Int32, Int32, Byte[], Int32)

計算輸入位元組陣列中指定區域的雜湊值,並將指定的輸入位元組陣列區域複製到指定的輸出位元組陣列區域。Computes the hash value for the specified region of the input byte array and copies the specified region of the input byte array to the specified region of the output byte array.

TransformFinalBlock(Byte[], Int32, Int32)

計算所指定位元組陣列中指定區域的雜湊值。Computes the hash value for the specified region of the specified byte array.

TryComputeHash(ReadOnlySpan<Byte>, Span<Byte>, Int32)
TryHashFinal(Span<Byte>, Int32)

明確介面實作

IDisposable.Dispose()

釋放 HashAlgorithm 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。Releases the unmanaged resources used by the HashAlgorithm and optionally releases the managed resources.

適用於

另請參閱