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:

#include <openssl/hmac.h>
#include <stdio.h>

int main() {
 const char key[] = "V0WX5fK~o6eEhr7hbs3ZeyxS";
 unsigned char result[EVP_MAX_MD_SIZE], hex_result[EVP_MAX_MD_SIZE*2];
 char* p;
 unsigned char data[100];
 unsigned int datalen, resultlen, i;
 HMAC_CTX ctx;
 // HMAC MD5
 // HMAC_Init(&ctx, key, sizeof(key), EVP_md5());

 HMAC_Init(&ctx, key, sizeof(key), EVP_sha1());

 // x_login^x_fp_sequence^x_fp_timestamp^x_amount^x_currency
 datalen = sprintf((char *)data, "%s^%s^%s^%s^%s", "WSP-ACTIV-70", "123", "1228774539", "100.00", "");

 HMAC_Update(&ctx,  data, datalen);
 HMAC_Final(&ctx, result, &resultlen);

 p = (char *)hex_result;
 for(i=0; i < resultlen; i++) {
   p += sprintf(p, "%02x", result[i]);
 p = '\0';
 printf("The hmac hash is %s\n", hex_result);

 return 0;

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