Merchant Hash Token Generation


Merchant Hash Token Generation

/* 
*secretKey - Lite Shared Secret 
*resource - /Lite/Authorise.aspx 
*applicationId - Lite Application Id 
*amount - Lite Order Amount 
*emailAddress - Ecom BillTo Online 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("x:", 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:{c0f9f3e2-b75c-4864-b6c6-df1372fbedb0} 
LiteSharedSecret:AFcWxV2NG9W4 
Lite_Order_mound:4130 
OnlineBilltoEmail:jdoe@mail.com 
Timestamp:1471358394 
Lite Transaction Token: 1471358394:8dd2f3c016662ef48743cf73a0b2e88de79b3e56791cbf48f8e0a688e363439915