/// <summary> /// Asynchronously computes the HMAC of a stream using the SHA512 algorithm. /// </summary> /// <param name="key">The HMAC key.</param> /// <param name="source">The stream to HMAC.</param> /// <param name="destination">The buffer to receive the HMAC value.</param> /// <param name="cancellationToken"> /// The token to monitor for cancellation requests. /// The default value is <see cref="System.Threading.CancellationToken.None" />. /// </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 ValueTask <int> HashDataAsync( ReadOnlyMemory <byte> key, Stream source, Memory <byte> destination, CancellationToken cancellationToken = default) { 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.HmacStreamAsync( HashAlgorithmNames.SHA512, HashSizeInBytes, key.Span, source, destination, cancellationToken)); }
/// <summary> /// Asynchronously computes the HMAC of a stream using the MD5 algorithm. /// </summary> /// <param name="key">The HMAC key.</param> /// <param name="source">The stream to HMAC.</param> /// <param name="cancellationToken"> /// The token to monitor for cancellation requests. /// The default value is <see cref="System.Threading.CancellationToken.None" />. /// </param> /// <returns>The HMAC 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 ValueTask<byte[]> HashDataAsync(ReadOnlyMemory<byte> key, Stream source, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(source); if (!source.CanRead) throw new ArgumentException(SR.Argument_StreamNotReadable, nameof(source)); return LiteHashProvider.HmacStreamAsync(HashAlgorithmNames.MD5, HashSizeInBytes, key.Span, source, cancellationToken); }
/// <summary> /// Computes the HMAC of a stream using the MD5 algorithm. /// </summary> /// <param name="key">The HMAC key.</param> /// <param name="source">The stream to HMAC.</param> /// <returns>The HMAC 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(ReadOnlySpan<byte> key, Stream source) { ArgumentNullException.ThrowIfNull(source); if (!source.CanRead) throw new ArgumentException(SR.Argument_StreamNotReadable, nameof(source)); return LiteHashProvider.HmacStream(HashAlgorithmNames.MD5, HashSizeInBytes, key, source); }
/// <summary> /// Asynchronously computes the hash of a stream using the SHA512 algorithm. /// </summary> /// <param name="source">The stream to hash.</param> /// <param name="cancellationToken"> /// The token to monitor for cancellation requests. /// The default value is <see cref="System.Threading.CancellationToken.None" />. /// </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 ValueTask <byte[]> HashDataAsync(Stream source, CancellationToken cancellationToken = default) { ArgumentNullException.ThrowIfNull(source); if (!source.CanRead) { throw new ArgumentException(SR.Argument_StreamNotReadable, nameof(source)); } return(LiteHashProvider.HashStreamAsync(HashAlgorithmNames.SHA512, HashSizeInBytes, source, cancellationToken)); }
/// <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 HMAC of a stream using the MD5 algorithm. /// </summary> /// <param name="key">The HMAC key.</param> /// <param name="source">The stream to HMAC.</param> /// <param name="destination">The buffer to receive the HMAC 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 HMAC /// size. The MD5 algorithm always produces a 128-bit HMAC, or 16 bytes. /// </p> /// <p>-or-</p> /// <p> /// <paramref name="source" /> does not support reading. /// </p> /// </exception> public static int HashData(ReadOnlySpan<byte> key, 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.HmacStream(HashAlgorithmNames.MD5, HashSizeInBytes, key, source, destination); }
/// <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)); }
public EvpHashProvider(string hashAlgorithmId) { _liteHash = LiteHashProvider.CreateHash(hashAlgorithmId); }
public HmacHashProvider(string hashAlgorithmId, ReadOnlySpan <byte> key) { _liteHmac = LiteHashProvider.CreateHmac(hashAlgorithmId, key); }
public AppleDigestProvider(string hashAlgorithmId) { _liteHash = LiteHashProvider.CreateHash(hashAlgorithmId); }