Search code examples
c++sha256hmac

Generate HMAC SHA256 hash using key in C++


I am looking for some function or a way that would return HMAC SHA256 hash in C++ using secret key. I have seen documentation of Crypto++ and OpenSSL but it does not accept an extra parameter of secret key for computation. Can someone help me by providing some info, code snippets or links.


Solution

  • OpenSSL docs for HMAC, clearly state the requirement of a 'key' as part of context initialization.

    int HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len,
                   const EVP_MD *md, ENGINE *impl);
    

    HMAC() computes the message authentication code of the n bytes at d using the hash function evp_md and the key key which is key_len bytes long.