HashAlgorithm 類別

定義

表示基類,其所有密碼編譯哈希演算法實作都必須衍生自此基類。

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

範例

以下程式碼範例計算 SHA256 陣列的雜湊值。 此範例假設存在預先定義的位元組陣列 dataArray[]SHA256 是 的 HashAlgorithm導出類。

HashAlgorithm sha = SHA256.Create();
byte[] result = sha.ComputeHash(dataArray);
Dim sha As SHA256 = SHA256.Create()
Dim result As Byte() = sha.ComputeHash(dataArray)

備註

雜湊函數是現代密碼學的基礎。 這些函式會將任意長度的二進位字串映射到固定長度的小二進位字串,稱為雜湊值。 密碼學雜湊函數具有計算上不可行的特性,即在計算上找不到兩個不同的輸入,且雜湊值相同。 雜湊函數常用於數位簽章及資料完整性。

雜湊值作為固定大小的唯一值,代表大量資料。 若對應資料也相符,則兩組資料的雜湊值應該相符。 資料中的小變動會導致雜湊值大幅且不可預測地變化。

由於 SHA-1 發生衝突問題,Microsoft 建議採用基於 SHA-256 或更高層級的安全性模型。

給實施者的注意事項

當你從 HashAlgorithm 該類別繼承時,必須覆寫以下成員: HashCore(Byte[], Int32, Int32)HashFinal()

建構函式

名稱 Description
HashAlgorithm()

初始化 HashAlgorithm 類別的新執行個體。

欄位

名稱 Description
HashSizeValue

代表計算出的雜湊碼大小(以位元為單位)。

HashValue

代表計算出的雜湊碼值。

State

代表雜湊計算的狀態。

屬性

名稱 Description
CanReuseTransform

會得到一個值,表示電流轉換是否可以重複使用。

CanTransformMultipleBlocks

當在派生類別中覆寫時,會得到一個值,表示是否可以轉換多個區塊。

Hash

取得計算出的雜湊碼值。

HashSize

取得計算出的雜湊碼大小(以位元為單位)。

InputBlockSize

當在衍生類別中覆寫時,會得到輸入區塊大小。

OutputBlockSize

當在衍生類別中覆寫時,會得到輸出區塊大小。

方法

名稱 Description
Clear()

釋放 HashAlgorithm 類別所使用的所有資源。

ComputeHash(Byte[], Int32, Int32)

計算指定位元組陣列中指定區域的雜湊值。

ComputeHash(Byte[])

計算指定位元組陣列的雜湊值。

ComputeHash(Stream)

計算指定 Stream 物件的雜湊值。

Create()

建立一個雜湊演算法預設實作的實例。

Create(String)

建立指定雜湊演算法實作的實例。

Dispose()

釋放目前類別實例 HashAlgorithm 所使用的所有資源。

Dispose(Boolean)

釋放 未管理的資源, HashAlgorithm 並可選擇性地釋放受管理資源。

Equals(Object)

判斷指定的 物件是否等於目前的物件。

(繼承來源 Object)
GetHashCode()

做為預設雜湊函式。

(繼承來源 Object)
GetType()

取得目前實例的 Type

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

當在衍生類別中覆寫時,會將寫入物件的資料導向計算雜湊演算法。

HashCore(ReadOnlySpan<Byte>)

將寫入物件的資料導向雜湊演算法以計算雜湊值。

HashFinal()

當在衍生類別中覆寫時,會在最後資料被密碼雜湊演算法處理後完成雜湊計算。

Initialize()

將雜湊演算法重置到初始狀態。

MemberwiseClone()

建立目前 Object的淺層複本。

(繼承來源 Object)
ToString()

傳回表示目前 物件的字串。

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

計算輸入位元組陣列指定區域的雜湊值,並將輸入位元組陣列的指定區域複製到輸出位元組陣列的指定區域。

TransformFinalBlock(Byte[], Int32, Int32)

計算指定位元組陣列中指定區域的雜湊值。

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

嘗試計算指定位元組陣列的雜湊值。

TryHashFinal(Span<Byte>, Int32)

嘗試在雜湊演算法處理最後資料後完成雜湊計算。

明確介面實作

名稱 Description
IDisposable.Dispose()

釋放 未管理的資源, HashAlgorithm 並可選擇性地釋放受管理資源。

適用於

另請參閱