Encoding a string in HMAC SHA256 [closed]

我怕爱的太早我们不能终老 提交于 2019-12-04 12:38:08
Jeffrey Hantin

HMAC and SHA256 are separate components in OpenSSL, you'll need to glue them together yourself. (Note that this uses the shorthand methods for doing everything in one shot with monolithic buffers; incremental processing is more complex.)

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

unsigned char* hmac_sha256(const void *key, int keylen,
                           const unsigned char *data, int datalen,
                           unsigned char *result, unsigned int* resultlen)
{
    return HMAC(EVP_sha256(), key, keylen, data, datalen, result, resultlen);
}

Even if your input is a string, the result is an arbitrary byte array; if that too needs to be a string then you'll have to apply some other transformation like hexadecimal expansion, Base64 or whatever suits your application.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!