Last active
December 24, 2023 14:52
-
-
Save Azadehkhojandi/50eaae4cf20b21faef186f2c8ee97873 to your computer and use it in GitHub Desktop.
Create SHA256 Signature for payment gateway (bendigo bank)
This file contains 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
do you have the any another language code for the same like python....