Generating x_fp_hash using C#

Created by Richard Moore, Modified on Wed, 12 Apr 2023 at 12:02 PM by Richard Moore

To generate x_fp_hash using C# please see the code below:


using System;
using System.Security;
using System.Security.Cryptography;
using System.Text;

class CalculateHash {

 static void Main() {
   StringBuilder sb = new StringBuilder();
   // x_login^x_fp_sequence^x_fp_timestamp^x_amount^x_currency
   String x_login = "WSP-ACTIV-70";
   String x_fp_sequence = "123";
   String x_fp_timestamp = "1228774539";
   String x_amount = "100.00";
   String x_currency = ""; // default empty

   sb.Append(x_login)
     .Append("^")
     .Append(x_fp_sequence)
     .Append("^")
     .Append(x_fp_timestamp)
     .Append("^")
     .Append(x_amount)
     .Append("^")
     .Append(x_currency);

   // Convert string to array of bytes.
   byte[] data = Encoding.UTF8.GetBytes(sb.ToString());

   // key
   byte[] key =  Encoding.UTF8.GetBytes("V0WX5fK~o6eEhr7hbs3ZeyxS");

   // Create HMAC-MD5 Algorithm;
   // HMACMD5 hmac = new HMACMD5(key);

   // Create HMAC-SHA1 Algorithm;
   HMACSHA1 hmac = new HMACSHA1(key);

   // Compute hash.
   byte[] hashBytes = hmac.ComputeHash(data);

   // Convert to HEX string.
   String  x_fp_hash = System.BitConverter.ToString(hashBytes).Replace("-", "").toLower();

   String msg = String.Format("x_login = {0}, x_fp_sequence = {1}, x_fp_timestamp = {2}, x_amount = {3}, x_currency= {4}.\n x_fp_hash = {5}", x_login, x_fp_sequence, x_fp_timestamp, x_amount, x_currency, x_fp_hash);
   System.Console.WriteLine(msg);

 }
}

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select atleast one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article