#include
#include
#include "openssl/evp.h"
void hmacsha256Encode(char *src,char *dst){
const char *key="123456abcdefg";
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, key, strlen(key), EVP_sha256(), NULL);
HMAC_Update(&ctx, (unsigned char*)src, strlen(src));
char output[128] = {0};
unsigned int length = 0;
HMAC_Final(&ctx, (unsigned char*)output, &length);
HMAC_CTX_cleanup(&ctx);
char m[64] = "";
for(int i = 0; i < length; i++) {
char s[10];
sprintf(s,"%02x",(unsigned int)output[i]);
strcat(m,s);
}
strcpy(dst,m);
}
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24