HashAlgorithm 類別

定義

代表基底類別,密碼編譯雜湊演算法的所有實作必須從它衍生。

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

範例

下列程式碼範例會 SHA256 計算陣列的雜湊。 此範例假設有預先定義的位元組陣列 dataArray[]SHA256 是 的 HashAlgorithm 衍生類別。

HashAlgorithm^ sha = SHA256::Create();
array<Byte>^ result = sha->ComputeHash( dataArray );
HashAlgorithm sha = SHA256.Create();
byte[] result = sha.ComputeHash(dataArray);
Dim sha As SHA256 = SHA256.Create()
Dim result As Byte() = sha.ComputeHash(dataArray)

備註

雜湊函式是新式密碼編譯的基礎。 這些函式會將任意長度的二進位字串對應至固定長度的小型二進位字串,稱為雜湊值。 密碼編譯雜湊函式具有無法計算的 屬性,可尋找雜湊為相同值的兩個相異輸入。 雜湊函式經常被用於數位簽章與資料完整性用途。

雜湊會當做固定大小的唯一值,代表大量資料。 如果對應的資料也相符,則兩組資料的雜湊應該相符。 對資料的小型變更會導致雜湊發生大量無法預測的變更。

由於 SHA1 的衝突問題,Microsoft 建議您使用以 SHA256 或更好的加密方式為基礎的安全性模型。

給實施者的注意事項

當您繼承自 類別時 HashAlgorithm ,必須覆寫下列成員: HashCore(Byte[], Int32, Int32)HashFinal()

建構函式

HashAlgorithm()

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

欄位

HashSizeValue

代表計算出來之雜湊碼的大小,以位元為單位。

HashValue

表示計算出來的雜湊碼的值。

State

表示雜湊計算的狀態。

屬性

CanReuseTransform

取得值,表示目前的轉換是否可重複使用。

CanTransformMultipleBlocks

在衍生類別中覆寫時,取得值以指出是否有多個區塊可被轉換。

Hash

取得計算出來之雜湊碼的值。

HashSize

取得計算出來之雜湊碼的大小,以位元為單位。

InputBlockSize

在衍生類別中覆寫時,取得輸入區塊的大小。

OutputBlockSize

在衍生類別中覆寫時,取得輸出區塊的大小。

方法

Clear()

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

ComputeHash(Byte[])

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

ComputeHash(Byte[], Int32, Int32)

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

ComputeHash(Stream)

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

ComputeHashAsync(Stream, CancellationToken)

以非同步方式計算指定 Stream 物件的雜湊值。

Create()
已淘汰.
已淘汰.

建立雜湊演算法的預設實作執行個體。

Create(String)
已淘汰.

建立雜湊演算法之指定實作的執行個體。

Dispose()

釋放 HashAlgorithm 類別目前的執行個體所使用的全部資源。

Dispose(Boolean)

釋放 HashAlgorithm 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

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)

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

明確介面實作

IDisposable.Dispose()

釋放 HashAlgorithm 所使用的 Unmanaged 資源,並選擇性地釋放 Managed 資源。

適用於

另請參閱