在我需要维护的代码中,有一点会破坏 Oauth 签名。我已将问题缩小到 HMAC-SHA1 摘要计算。有这样的代码:
char key[256]="", base[1024]="";
char hmacsha1[1024]="", hmac_base64[1024]="";
unsigned int hmacsha1_len;
HMAC(EVP_sha1(), key, strlen(key), (unsigned char *)data, strlen(data), (unsigned char *)hmacsha1, &hmacsha1_len);
gBase64CRInclude = FALSE;
BPos = 0;
XPos = 0;
SPos = 0;
for (i=0;i<hmacsha1_len;i++) {
ch = hmacsha1[i];
BBuf[BPos++] = ch;
if (BPos == 3) {
encodebase64Mem(hmac_base64, &SPos);
BBuf[0]=BBuf[1]=BBuf[2]=BBuf[3] = 0;
}
}
encodebase64Mem(hmac_base64, &SPos);
hmac_base64[SPos] = 0;
printf("HMAC-SHA1: %s\n", hmac_base64);
现在encodebase64Mem()
似乎没问题,因为其他字符串编码正确。我已经看到了类似的例子,但仍然无法弄清楚为什么摘要计算不正确。感谢任何帮助,谢谢!