HashAlgorithm 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示基類,其所有密碼編譯哈希演算法實作都必須衍生自此基類。
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 |
|---|---|
| IDisposable.Dispose() |
釋放 未管理的資源, HashAlgorithm 並可選擇性地釋放受管理資源。 |