Instantly share code, notes, and snippets.

Embed
What would you like to do?
Create SHA256 Signature for payment gateway (bendigo bank)
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
var hexHash = "";
using (var hasher = new HMACSHA256(convertedHash))
{
var hashValue = hasher.ComputeHash(Encoding.UTF8.GetBytes(message));
hexHash = hashValue.Aggregate(hexHash, (current, b) => current + b.ToString("X2"));
}
return hexHash;
}
@AMHZR

This comment has been minimized.

AMHZR commented Nov 9, 2017

do you have the any another language code for the same like python....

@gjain0

This comment has been minimized.

@AMHZR

This comment has been minimized.

AMHZR commented Nov 9, 2017

@gjain0
you are awesome.. thanks..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment