SHA256HashGenerator.cs 606 B

1234567891011121314151617181920212223242526
  1. using System.Text;
  2. using System.Security.Cryptography;
  3. namespace BubbleSocketCore.Library
  4. {
  5. public class SHA256HashGenerator
  6. {
  7. public static SHA256HashGenerator GetInstance()
  8. {
  9. return new SHA256HashGenerator();
  10. }
  11. public string Get(string text)
  12. {
  13. using (SHA256 hash = SHA256.Create())
  14. {
  15. byte[] hashValue = hash.ComputeHash(Encoding.UTF8.GetBytes(text));
  16. StringBuilder builder = new StringBuilder();
  17. for (int i = 0; i < hashValue.Length; i++)
  18. {
  19. builder.Append(hashValue[i].ToString("X2")); //Format as hexidecimal
  20. }
  21. return builder.ToString();
  22. }
  23. }
  24. }
  25. }