Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C+中的HMAC-SHA1+;使用OpenSSL_C++_Openssl_Hmacsha1 - Fatal编程技术网

C++ C+中的HMAC-SHA1+;使用OpenSSL

C++ C+中的HMAC-SHA1+;使用OpenSSL,c++,openssl,hmacsha1,C++,Openssl,Hmacsha1,在我需要维护的代码中,有一点破坏了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), (unsign

在我需要维护的代码中,有一点破坏了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);
char键[256]=“”,基[1024]=“”;
字符hmacsha1[1024]=“”,hmac_base64[1024]=“”;
无符号整数hmacsha1_len;
HMAC(EVP_sha1(),key,strlen(key),(unsigned char*)数据,strlen(data),(unsigned char*)hmacsha1,&hmacsha1_len);
gBase64CRInclude=假;
BPos=0;
XPos=0;
SPos=0;

对于(i=0;我能举个例子吗?给定一个特定的输入,你得到什么作为输出,你期望什么?除了
key
是一个空字符串之外,
HMAC()
调用看起来不错。另外,为什么
hmacsha1
的值为1024字节?您知道它将是160字节。密钥和数据只是OAuth的常用字符串,您可以将其作为加密密钥和消息体。我怀疑签名的base64编码没有正确完成。可能尝试在y中打印HMAC调用的结果我们的代码,看看它们是否相同,然后你可以责怪base64。谢谢!结果我只是忘记在密钥末尾附加“&”,这导致签名不正确。