1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
protected void Page_Load(object sender, EventArgs e)
{
frm.Action = "https://preprod-tpeweb.paybox.com/cgi/MYchoix_pagepaiement.cgi";
//Init the ASCII Encoder
ASCIIEncoding encoder = new ASCIIEncoding();
string clearMessage = "PBX_SITE=1999888";
//Transform the clear query string to a byte array
byte[] messageBytes = encoder.GetBytes(clearMessage);
//Transform the secret key stored as Hexadecimal string to a byte array
string secretKeyString = "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF";
byte[] secretKeyBytes = new byte[secretKeyString.Length/2];
for (int index = 0; index < secretKeyBytes.Length; index++)
{
string byteValue = secretKeyString.Substring(index*2, 2);
secretKeyBytes[index] = byte.Parse(byteValue, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
}
//Init the Hmac SHA512 generator with the key
HMACSHA512 hmacsha512 = new HMACSHA512(secretKeyBytes);
//Hash the message
byte[] hashValue = hmacsha512.ComputeHash(messageBytes);
//Transform the hash bytes array to a string string
string hmac = "";
foreach (byte x in hashValue)
{
hmac += String.Format("{0:x2}", x);
}
//Force the case of the HMAC key to Uppercase
PBX_HMAC.Value = hmac.ToUpper();
} |
Partager