Skip to content

Instantly share code, notes, and snippets.

@hartviglarsen
Created September 19, 2019 07:44
Show Gist options
  • Save hartviglarsen/656f581ca2e491e662426c8b302403df to your computer and use it in GitHub Desktop.
Save hartviglarsen/656f581ca2e491e662426c8b302403df to your computer and use it in GitHub Desktop.
Simple string hash
using System;
using System.Security.Cryptography;
using System.Text;
namespace Security
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("hello@world.com".Hash());
}
}
public static class StringExtensions
{
public static string Hash(this string input)
{
var builder = new StringBuilder();
using (var algorithm = SHA256.Create())
{
var bytes = algorithm.ComputeHash(Encoding.UTF8.GetBytes(input));
foreach (var b in bytes)
{
builder.Append(b.ToString("X2"));
}
return builder.ToString();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment