Check if OpenSSL is installed:
sudo apt-get install OpenSSL
If you have installed, do the following:
sudo apt-get install Libssl-dev
sudo apt-get install libssl0.9.8
Install GTK + Development Library under Ubuntu
sudo apt-get install Libgtk2.0-dev
Code:
#include <stdio.h> #include <string.h> #include <openssl/hmac.h > int main () {//The secret key for hashing char key[] = "f5f48fc13505425891fb429f99d66171"; char user[] = "Fazio "; Char api_key[] = "4894A1A7B78E44B6A449C5299B1AFC24"; char nonce[] = "000000"; char *data = malloc (strlen (user) +strlen (API _key) +strlen (nonce) +1); strcpy (Data,user); strcat (Data,api_key) strcat (data,nonce);p rintf ("%s \ n", data); unsigned char* result; unsigned int len = 65; result = (unsigned char*) malloc (sizeof (char) * len); Hmac_ctx CTX; Hmac_ctx_init (&CTX); HMAC_INIT_EX (&ctx, Key, strlen (key), evp_sha256 (), NULL); Hmac_update (&ctx, (unsigned char*) data, strlen (data)); Hmac_final (&ctx, result, &len); Hmac_ctx_cleanup (&CTX); printf ("HMAC Digest:"); int i; for (i = 0; I! = len; i++) printf ("%02x", (unsigned int) result[i]); printf ("\ n"); Free (result); return 0;}
Compilation: Gcc-o test Test.c-lssl-lcrypto
Operation Result:
fazio4894a1a7b78e44b6a449c5299b1afc24000000
HMAC DIGEST:6764F0C105DCFA9FC143AEA534232C297AB2BA4E362FD87AF5EB0A26B270E0EB
Install openssl&& compile run test code under Ubuntu