CryptographicOperations.TryHashData Method

Definition

Attempts to compute the hash of data.

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

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.

bytesWritten
Int32

When this method returns, the total number of bytes written into destination.

Returns

false if destination is too small to hold the calculated hash, true otherwise.

Exceptions

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

Product Versions
.NET 9