Created
September 19, 2019 07:44
-
-
Save hartviglarsen/656f581ca2e491e662426c8b302403df to your computer and use it in GitHub Desktop.
Simple string hash
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Security.Cryptography; | |
using System.Text; | |
namespace Security | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Console.WriteLine("[email protected]".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