HashAlgorithm HashAlgorithm HashAlgorithm HashAlgorithm Class

定義

代表基底類別,密碼編譯雜湊演算法的所有實作必須從它衍生。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
繼承
HashAlgorithmHashAlgorithmHashAlgorithmHashAlgorithm
衍生
屬性
實作

範例

下列程式碼範例會計算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.

給繼承者的注意事項

當您繼承自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() HashAlgorithm() HashAlgorithm()

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

欄位

HashSizeValue HashSizeValue HashSizeValue HashSizeValue

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

HashValue HashValue HashValue HashValue

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

State State State State

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

屬性

CanReuseTransform CanReuseTransform CanReuseTransform CanReuseTransform

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

CanTransformMultipleBlocks CanTransformMultipleBlocks CanTransformMultipleBlocks CanTransformMultipleBlocks

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

Hash Hash Hash Hash

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

HashSize HashSize HashSize HashSize

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

InputBlockSize InputBlockSize InputBlockSize InputBlockSize

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

OutputBlockSize OutputBlockSize OutputBlockSize OutputBlockSize

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

方法

Clear() Clear() Clear() Clear()

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

ComputeHash(Byte[]) ComputeHash(Byte[]) ComputeHash(Byte[]) ComputeHash(Byte[])

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

ComputeHash(Byte[], Int32, Int32) ComputeHash(Byte[], Int32, Int32) ComputeHash(Byte[], Int32, Int32) ComputeHash(Byte[], Int32, Int32)

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

ComputeHash(Stream) ComputeHash(Stream) ComputeHash(Stream) ComputeHash(Stream)

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

Create() Create() Create() Create()

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

Create(String) Create(String) Create(String) Create(String)

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

Dispose() Dispose() Dispose() Dispose()

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

Dispose(Boolean) Dispose(Boolean) Dispose(Boolean) Dispose(Boolean)

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

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

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

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

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

(Inherited from Object)
GetType() GetType() GetType() GetType()

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

(Inherited from Object)
HashCore(Byte[], Int32, Int32) HashCore(Byte[], Int32, Int32) HashCore(Byte[], Int32, Int32) 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>) HashCore(ReadOnlySpan<Byte>) HashCore(ReadOnlySpan<Byte>) HashCore(ReadOnlySpan<Byte>)
HashFinal() HashFinal() HashFinal() HashFinal()

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

Initialize() Initialize() Initialize() Initialize()

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

MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

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

(Inherited from Object)
ToString() ToString() ToString() ToString()

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

(Inherited from Object)
TransformBlock(Byte[], Int32, Int32, Byte[], Int32) TransformBlock(Byte[], Int32, Int32, Byte[], Int32) TransformBlock(Byte[], Int32, Int32, Byte[], Int32) 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) TransformFinalBlock(Byte[], Int32, Int32) TransformFinalBlock(Byte[], Int32, Int32) TransformFinalBlock(Byte[], Int32, Int32)

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

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

明確介面實作

IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose() IDisposable.Dispose()

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

適用於

另請參閱