小编Yul*_*lia的帖子

HMAC-SHA256 in C with OpenSSL - 如何获得正确的输出

这是我用来编码字符串的函数:

\n\n
#include <openssl/evp.h>\n#include <openssl/hmac.h>\n\nunsigned char *mx_hmac_sha256(const void *key, int keylen,\n                              const unsigned char *data, int datalen,\n                              unsigned char *result, unsigned int *resultlen) {\n    return HMAC(EVP_sha256(), key, keylen, data, datalen, result, resultlen);\n}\n
Run Code Online (Sandbox Code Playgroud)\n\n

这是我如何调用它并检查结果:

\n\n
char *key = strdup("security is awesome");\nint keylen = strlen(key);\nconst unsigned char *data = (const unsigned char *)strdup("this is highly sensitive user data");\nint datalen = strlen((char *)data);\nunsigned char *result = NULL;\nunsigned int resultlen = -1;\n\nresult = mx_hmac_sha256((const void *)key, keylen, data, datalen, result, &resultlen);\n\nfor (unsigned int …
Run Code Online (Sandbox Code Playgroud)

c encryption openssl cryptography hmac

9
推荐指数
1
解决办法
1万
查看次数

标签 统计

c ×1

cryptography ×1

encryption ×1

hmac ×1

openssl ×1