有时你必须实现C代码和加密,所以我的hmac256或sha2_hmac实现的C代码实现有问题:
unsigned char key[19] = { "abcdef" };
size_t keylen = 18;
unsigned char input[64] = {"123456789"};
size_t ilen = 63;
unsigned char output[32];
int is224 = 0;
sha2_hmac(key, keylen, input, ilen, output, is224);
char result[64] = {};
char result2[64] = {};
for(int j = 0; j < 32; j++) {
sprintf(result, "%X", output[j]);
strcat(result2, result);
}
但是当我将它与C#代码进行比较时,结果太短了。
答案 0 :(得分:2)
您必须像这样调整sprintf()
函数调用:
sprintf(result, "%02X", output[j]);