CryptographicOperations.HashData Method

Definition

Overloads

HashData(HashAlgorithmName, Byte[])

Computes the hash of data.

HashData(HashAlgorithmName, Stream)

Computes the hash of a stream.

HashData(HashAlgorithmName, ReadOnlySpan<Byte>)

Computes the hash of data.

HashData(HashAlgorithmName, Stream, Span<Byte>)

Computes the hash of a stream.

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

Computes the hash of data.

HashData(HashAlgorithmName, Byte[])

Source:
CryptographicOperations.cs

Computes the hash of data.

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

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the hash.

source
Byte[]

The data to hash.

Returns

Byte[]

The hash of the data.

Exceptions

source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

HashData(HashAlgorithmName, Stream)

Source:
CryptographicOperations.cs

Computes the hash of a stream.

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

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the hash.

source
Stream

The stream to hash.

Returns

Byte[]

The hash of the data.

Exceptions

source is null.

-or-

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

-or-

source does not support reading.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

HashData(HashAlgorithmName, ReadOnlySpan<Byte>)

Source:
CryptographicOperations.cs

Computes the hash of data.

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

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the hash.

source
ReadOnlySpan<Byte>

The data to hash.

Returns

Byte[]

The hash of the data.

Exceptions

hashAlgorithm has a Name that is null.

hashAlgorithm has a Name that is empty.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

HashData(HashAlgorithmName, Stream, Span<Byte>)

Source:
CryptographicOperations.cs

Computes the hash of a stream.

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

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the hash.

source
Stream

The stream to hash.

destination
Span<Byte>

The buffer to receive the hash value.

Returns

The total number of bytes written to destination.

Exceptions

source is null.

-or-

hashAlgorithm has a Name that is null.

The buffer in destination is too small to hold the calculated hash size.

-or-

hashAlgorithm has a Name that is empty.

-or-

source does not support reading.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10

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

Source:
CryptographicOperations.cs

Computes the hash of data.

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

Parameters

hashAlgorithm
HashAlgorithmName

The algorithm used to compute the hash.

source
ReadOnlySpan<Byte>

The data to hash.

destination
Span<Byte>

The buffer to receive the hash value.

Returns

The total number of bytes written to destination.

Exceptions

The buffer in destination is too small to hold the calculated hash size.

-or-

hashAlgorithm has a Name that is empty.

hashAlgorithm has a Name that is null.

hashAlgorithm specifies a hash algorithm not supported by the current platform.

hashAlgorithm specifies an unknown hash algorithm.

Applies to

.NET 10 and .NET 9
Product Versions
.NET 9, 10