/*
*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;