CryptographicOperations.HashData 方法

定義

多載

HashData(HashAlgorithmName, Byte[])

來源:
CryptographicOperations.cs

計算數據的哈希。

public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, byte[] source);

參數

hashAlgorithm
HashAlgorithmName

用來計算哈希的演算法。

source
Byte[]

要哈希的數據。

傳回

Byte[]

數據的哈希。

例外狀況

source null

-或-

hashAlgorithm 具有 nullName

hashAlgorithm 具有空白的 Name

hashAlgorithm 指定目前平台不支援的哈希演算法。

hashAlgorithm 指定未知的哈希演算法。

適用於

.NET 10 和 .NET 9
產品 版本
.NET 9, 10

HashData(HashAlgorithmName, Stream)

來源:
CryptographicOperations.cs

計算數據流的哈希。

public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source);

參數

hashAlgorithm
HashAlgorithmName

用來計算哈希的演算法。

source
Stream

要哈希的數據流。

傳回

Byte[]

數據的哈希。

例外狀況

source null

-或-

hashAlgorithm 具有 nullName

hashAlgorithm 具有空白的 Name

-或-

source 不支援讀取。

hashAlgorithm 指定目前平台不支援的哈希演算法。

hashAlgorithm 指定未知的哈希演算法。

適用於

.NET 10 和 .NET 9
產品 版本
.NET 9, 10

HashData(HashAlgorithmName, ReadOnlySpan<Byte>)

來源:
CryptographicOperations.cs

計算數據的哈希。

public static byte[] HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> source);

參數

hashAlgorithm
HashAlgorithmName

用來計算哈希的演算法。

source
ReadOnlySpan<Byte>

要哈希的數據。

傳回

Byte[]

數據的哈希。

例外狀況

hashAlgorithm 具有 nullName

hashAlgorithm 具有空白的 Name

hashAlgorithm 指定目前平台不支援的哈希演算法。

hashAlgorithm 指定未知的哈希演算法。

適用於

.NET 10 和 .NET 9
產品 版本
.NET 9, 10

HashData(HashAlgorithmName, Stream, Span<Byte>)

來源:
CryptographicOperations.cs

計算數據流的哈希。

public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, System.IO.Stream source, Span<byte> destination);

參數

hashAlgorithm
HashAlgorithmName

用來計算哈希的演算法。

source
Stream

要哈希的數據流。

destination
Span<Byte>

要接收哈希值的緩衝區。

傳回

寫入至 destination的位元組總數。

例外狀況

source null

-或-

hashAlgorithm 具有 nullName

destination 中的緩衝區太小,無法保存導出的哈希大小。

-或-

hashAlgorithm 具有空白的 Name

-或-

source 不支援讀取。

hashAlgorithm 指定目前平台不支援的哈希演算法。

hashAlgorithm 指定未知的哈希演算法。

適用於

.NET 10 和 .NET 9
產品 版本
.NET 9, 10

HashData(HashAlgorithmName, ReadOnlySpan<Byte>, Span<Byte>)

來源:
CryptographicOperations.cs

計算數據的哈希。

public static int HashData(System.Security.Cryptography.HashAlgorithmName hashAlgorithm, ReadOnlySpan<byte> source, Span<byte> destination);

參數

hashAlgorithm
HashAlgorithmName

用來計算哈希的演算法。

source
ReadOnlySpan<Byte>

要哈希的數據。

destination
Span<Byte>

要接收哈希值的緩衝區。

傳回

寫入至 destination的位元組總數。

例外狀況

destination 中的緩衝區太小,無法保存導出的哈希大小。

-或-

hashAlgorithm 具有空白的 Name

hashAlgorithm 具有 nullName

hashAlgorithm 指定目前平台不支援的哈希演算法。

hashAlgorithm 指定未知的哈希演算法。

適用於

.NET 10 和 .NET 9
產品 版本
.NET 9, 10