Skip to content

Instantly share code, notes, and snippets.

@farukcan
Created November 3, 2022 14:38
Show Gist options
  • Save farukcan/f1af332cf951f5a2174236f129aaaf30 to your computer and use it in GitHub Desktop.
Save farukcan/f1af332cf951f5a2174236f129aaaf30 to your computer and use it in GitHub Desktop.
C# SHA256 Helper
using System.Security.Cryptography;
using System.Text;
namespace FarukCan.Helpers
{
public static class Sha256Helper
{
public static string GetSha256Hash(this string input,string salt="")
{
using (SHA256 sha256Hash = SHA256.Create())
{
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input+salt));
StringBuilder builder = new StringBuilder();
for (int i = 0; i < bytes.Length; i++)
{
builder.Append(bytes[i].ToString("x2"));
}
return builder.ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment