StreamExt.cs 589 B

123456789101112131415161718192021
  1. using System;
  2. using System.IO;
  3. using System.Security.Cryptography;
  4. namespace Quadarax.Foundation.Core.IO
  5. {
  6. public static class StreamExt
  7. {
  8. public static string GetStreamCalculatedHash(this Stream stream, HashAlgorithm algorithm)
  9. {
  10. if (stream == null)
  11. throw new ArgumentNullException(nameof(stream));
  12. if (algorithm == null)
  13. throw new ArgumentNullException(nameof(algorithm));
  14. return BitConverter.ToString(algorithm.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
  15. }
  16. }
  17. }