Skip to content

Instantly share code, notes, and snippets.

@dannylloyd
Created July 16, 2020 15:44
Show Gist options
  • Save dannylloyd/d6076b5a2e1a9226a1e456014e276d60 to your computer and use it in GitHub Desktop.
Save dannylloyd/d6076b5a2e1a9226a1e456014e276d60 to your computer and use it in GitHub Desktop.
Hashes string using salt and returns string
private static string CalcHMACSHA256Hash(string plaintext, string salt)
{
string result = "";
var enc = Encoding.Default;
byte[] baText2BeHashed = enc.GetBytes(plaintext),
baSalt = enc.GetBytes(salt);
System.Security.Cryptography.HMACSHA256 hasher = new HMACSHA256(baSalt);
byte[] baHashedText = hasher.ComputeHash(baText2BeHashed);
result = string.Join("", baHashedText.ToList().Select(b => b.ToString("x2")).ToArray());
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment