Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string CreateSHA256Signature(string key, string message)
- {
- // Hex Decode the Secure Secret for use in using the HMACSHA256 hasher
- // hex decoding eliminates this source of error as it is independent of the character encoding
- // hex decoding is precise in converting to a byte array and is the preferred form for representing binary values as hex strings.
- var convertedHash = new byte[key.Length / 2];
- for (var i = 0; i < key.Length / 2; i++)
- {
- convertedHash[i] = (byte)int.Parse(key.Substring(i * 2, 2), System.Globalization.NumberStyles.HexNumber);
- }
- // Create secureHash on string
- string hexHash = "";
- using (HMACSHA256 hasher = new HMACSHA256(convertedHash))
- {
- byte[] hashValue = hasher.ComputeHash(Encoding.UTF8.GetBytes(message));
- foreach (byte b in hashValue)
- {
- hexHash += b.ToString("X2");
- }
- }
- return hexHash;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement