E-xact Knowledge Base

Sample code for generating the hash for Hosted Checkout using C

To generate x_fp_hash using C, please see the snippet below:

----------------------------------------------------------------------------------------------

#include
#include

int main() {To generate x_fp_hash using C, please see the snippet below:

----------------------------------------------------------------------------------------------

#include
#include

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 SHA1
 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);

 HMAC_cleanup(&ctx);
 return 0;
}



----------------------------------------------------------------------------------------------
 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 SHA1
 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);

 HMAC_cleanup(&ctx);
 return 0;
}



----------------------------------------------------------------------------------------------


Article Details

Last Updated
20th of May, 2010

Would you like to...

Print this page Print this page

Email this page Email this page

Post a comment Post a comment

Subscribe me

Add to favorites Add to favorites

Remove Highlighting Remove Highlighting

Edit this Article

Quick Edit

Export to PDF

User Opinions (0 votes)

No users have voted.

How would you rate this answer?



Thank you for rating this answer.

Continue