PasswordHasher.cs 675 B

123456789101112131415161718192021222324
  1. using System.Security.Cryptography;
  2. using System.Text;
  3. namespace ComputerShopWpf.Services
  4. {
  5. public static class PasswordHasher
  6. {
  7. public static string ComputeSha256Hash(string rawData)
  8. {
  9. using (SHA256 sha256Hash = SHA256.Create())
  10. {
  11. byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(rawData ?? string.Empty));
  12. StringBuilder builder = new StringBuilder();
  13. for (int i = 0; i < bytes.Length; i++)
  14. {
  15. builder.Append(bytes[i].ToString("x2"));
  16. }
  17. return builder.ToString();
  18. }
  19. }
  20. }
  21. }