The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SHA1.cs 811B

123456789101112131415161718192021222324252627282930313233
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Security.Cryptography;
  6. using System.Text;
  7. namespace Teknik.Utilities.Cryptography
  8. {
  9. public class SHA1
  10. {
  11. public static string Hash(string text)
  12. {
  13. using (var ms = new MemoryStream(Encoding.UTF8.GetBytes(text)))
  14. {
  15. return Hash(ms);
  16. }
  17. }
  18. public static string Hash(Stream stream)
  19. {
  20. var hash = default(string);
  21. using (var algo = System.Security.Cryptography.SHA1.Create())
  22. {
  23. var hashBytes = algo.ComputeHash(stream);
  24. // Return as hexadecimal string
  25. hash = hashBytes.ToHex();
  26. }
  27. return hash;
  28. }
  29. }
  30. }