Created
July 16, 2020 15:44
-
-
Save dannylloyd/d6076b5a2e1a9226a1e456014e276d60 to your computer and use it in GitHub Desktop.
Hashes string using salt and returns string
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
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