/// <summary> /// Computes the hash of a stream using the SHA512 algorithm. /// </summary> /// <param name="source">The stream to hash.</param> /// <returns>The hash of the data.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="source" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// <paramref name="source" /> does not support reading. /// </exception> public static byte[] HashData(Stream source) { ArgumentNullException.ThrowIfNull(source); if (!source.CanRead) { throw new ArgumentException(SR.Argument_StreamNotReadable, nameof(source)); } return(LiteHashProvider.HashStream(HashAlgorithmNames.SHA512, HashSizeInBytes, source)); }
/// <summary> /// Computes the hash of a stream using the SHA512 algorithm. /// </summary> /// <param name="source">The stream to hash.</param> /// <param name="destination">The buffer to receive the hash value.</param> /// <returns>The total number of bytes written to <paramref name="destination" />.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="source" /> is <see langword="null" />. /// </exception> /// <exception cref="ArgumentException"> /// <p> /// The buffer in <paramref name="destination"/> is too small to hold the calculated hash /// size. The SHA512 algorithm always produces a 512-bit hash, or 64 bytes. /// </p> /// <p>-or-</p> /// <p> /// <paramref name="source" /> does not support reading. /// </p> /// </exception> public static int HashData(Stream source, Span <byte> destination) { ArgumentNullException.ThrowIfNull(source); if (destination.Length < HashSizeInBytes) { throw new ArgumentException(SR.Argument_DestinationTooShort, nameof(destination)); } if (!source.CanRead) { throw new ArgumentException(SR.Argument_StreamNotReadable, nameof(source)); } return(LiteHashProvider.HashStream(HashAlgorithmNames.SHA512, HashSizeInBytes, source, destination)); }