C++ OpenSSL 1.0 迁移到 3.0
C++ OpenSSL 1.0 migration to 3.0
我正在尝试制作一个机器人来使用 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
看这里:
听起来您正在使用 Microsoft Visual Studio C++ 进行编译。您可以使用 #pragma warning(disable : 4996)
消除 C4996“错误”
“我好像下载了 3.0 alpha 版本”
使用 Open SSL 1.1 可能会更好:
08-Dec-2020 OpenSSL 1.1.1i is now available, including bug and security
fixes
'希望对您有所帮助!请 post 支持您的结果。
我正在尝试制作一个机器人来使用 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
看这里:
听起来您正在使用 Microsoft Visual Studio C++ 进行编译。您可以使用
消除 C4996“错误”#pragma warning(disable : 4996)
“我好像下载了 3.0 alpha 版本”
使用 Open SSL 1.1 可能会更好:
08-Dec-2020 OpenSSL 1.1.1i is now available, including bug and security fixes
'希望对您有所帮助!请 post 支持您的结果。