我正在尝试创建一个机器人来访问 BitStamp API 并执行操作 (https://www.bitstamp.net/api/),但我遇到了障碍。
在链接的页面中,他们展示了如何使用 c++(V2 版本)进行身份验证的示例。我在使用 openSSL 进行身份验证时遇到这部分问题:
HMAC_CTX ctx;
HMAC_CTX_init(&ctx);
HMAC_Init_ex(&ctx, api_secret.c_str(), api_secret.length(), EVP_sha256(), NULL);
HMAC_Update(&ctx, (unsigned char*)data_to_sign.c_str(), data_to_sign.length());
HMAC_Final(&ctx, result, &len);
HMAC_CTX_cleanup(&ctx);
std::string x_auth_signature = b2a_hex( (char *)result, 32 );
free(result);
和
std::string b2a_hex(char *byte_arr, int n)
{
const static std::string hex_codes = "0123456789abcdef";
std::string hex_string;
for ( int i = 0; i < n ; ++i ) {
unsigned char bin_value = byte_arr[i];
hex_string += hex_codes[( bin_value >> 4 ) & 0x0F];
hex_string += hex_codes[bin_value & 0x0F];
}
return hex_string;
}
使用openSSL 3.0,似乎HMAC_CTX已被弃用。
编译时出现以下错误消息:
错误 C4996“HMAC_Update”:自 OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 70
错误 C4996 'HMAC_Init_ex':自 OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 69
错误 C4996“HMAC_Final”:自 OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 71
错误 C4996 'HMAC_CTX_reset':自 OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 72
错误 C4996 'HMAC_CTX_new':自 OpenSSL 3.0 StonksBot C:\CodeProjects\StonksBot\StonksBot\Source\StonksBot\Requests\AuthenticationRequest.cpp 68
我在互联网上搜索任何迁移技巧,但我找不到任何东西。任何好心人都可以帮助我或指出如何将这段代码迁移到 openSSL3.0 支持的代码吗?
好的,有几个问题:
Error C4996 'HMAC_Update': Since OpenSSL 3.0
看这里:https://stackoverflow.com/a/20448142/421195
听起来您正在使用 Microsoft Visual Studio C++ 进行编译。您也许可以使用
#pragma warning(disable : 4996)
消除 C4996“错误”
好像我下载的是3.0 alpha版本
使用 OpenSSL 1.1 可能会有更好的运气:
2020 年 12 月 8 日 OpenSSL 1.1.1i 现已推出,包括错误和安全修复