我正在尝试创建一个机器人来访问 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);
Run Code Online (Sandbox Code Playgroud)
和
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;
}
Run Code Online (Sandbox Code Playgroud)
使用 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
听起来您正在使用 Microsoft Visual Studio C++ 进行编译。您也许可以消除 C4996“错误”:#pragma warning(disable : 4996)
“看来我下载的是 3.0 alpha 版本”
使用 Open SSL 1.1 可能会有更好的运气:
2020 年 12 月 8 日 OpenSSL 1.1.1i 现已推出,包括错误和安全修复
'希望有帮助!请发回您的结果。
| 归档时间: |
|
| 查看次数: |
10097 次 |
| 最近记录: |