Merchant Hash Token Generation



Merchant Hash Token Generation

/* 
*secretKey - Lite Shared Secret 
*resource - /Lite/Authorise.aspx 
*applicationId - {435407B0-8A28-4152-9649-A932423F72EB}
*amount - Lite_Order_Amount 
*emailAddress - Ecom_BillTo_Email 
*/
public static string GenerateTransactionToken(string secretKey, string resource, string applicationId, string amount, string emailAddress) 

string time = Convert.ToString(UnixTimeStampUTC()); 
string token = secretKey + time + resource + applicationId + amount + emailAddress; 
return String.Concat(time, ":" + GetHashSha256(token)); 
}
public static Int32 UnixTimeStampUTC() 

Int32 unixTimeStamp; 
DateTime currentTime = DateTime.Now; 
DateTime zuluTime = currentTime.ToUniversalTime(); 
DateTime unixEpoch = new DateTime(1970, 1, 1);
unixTimeStamp = (Int32)(zuluTime.Subtract(unixEpoch)).TotalSeconds; 
return unixTimeStamp; 
}
public static string GetHashSha256(string text) 

35 byte[] bytes = Encoding.ASCII.GetBytes(text); 
SHA256Managed hashstring = new SHA256Managed (); 
byte[] hash = hashstring.ComputeHash(bytes); 
string hashString = string.Empty;
foreach (byte x in hash) 

hashString += String.Format("{0:x2}", x);

return hashString;
 

Sample Code:

ApplicationId:{435407B0-8A28-4152-9649-A932423F72EB}

LiteSharedSecret:AFcWxV2NG9W4 
Resource: /Lite/Authorise.aspx
Lite_Order_Amount:4130 
Ecom_BillTo_Email: joedoe@mail.com
Timestamp:1471358394 
LiteTransaction Token -  1471358394:be3350759bb0e41d1ac4a0b906ff9e1063bebbfc014753b713f0d3c49609ce44