Skip to content

Instantly share code, notes, and snippets.

@iaoedsz2008
Created May 6, 2019 03:01
Show Gist options
  • Save iaoedsz2008/f240d471afa9bfd175fc0f331d337071 to your computer and use it in GitHub Desktop.
Save iaoedsz2008/f240d471afa9bfd175fc0f331d337071 to your computer and use it in GitHub Desktop.
void hmac_sha256 (const unsigned char* input, int inputlength, unsigned char* output, unsigned int* outputlength)
{
const EVP_MD* engine = EVP_sha256 ();
#if OPENSSL_VERSION_NUMBER < 0x10100000L
HMAC_CTX ctx;
HMAC_CTX_init (&ctx);
HMAC_Init_ex (&ctx, API_SECRET_KEY, strlen (API_SECRET_KEY), engine, NULL);
HMAC_Update (&ctx, (const unsigned char*)input, inputlength);
HMAC_Final (&ctx, output, outputlength);
#else
HMAC_CTX* ctx = HMAC_CTX_new ();
HMAC_Init_ex (ctx, API_SECRET_KEY, strlen (API_SECRET_KEY), engine, NULL);
HMAC_Update (ctx, (const unsigned char*)input, inputlength);
HMAC_Final (ctx, output, outputlength);
HMAC_CTX_free (ctx);
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment