gpt4 book ai didi

c - C 中的加密 hmac 结果比 C# 短

转载 作者:太空宇宙 更新时间:2023-11-03 23:31:30 24 4
gpt4 key购买 nike

有时您必须实现 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# 代码进行比较时,结果太短了。

最佳答案

您必须像这样调整您的 sprintf() 函数调用:

sprintf(result, "%02X", output[j]);

关于c - C 中的加密 hmac 结果比 C# 短,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14237622/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com