EVP_get_cipherbyname 始终返回 null

Con*_*lor 5 c macos openssl macos-sierra

我在 macOS 上调用时遇到问题EVP_get_cipherbyname

const char *cipher_str = "aes-256-cbc";
const evp_cipher_st *cipher1 = EVP_aes_256_cbc();
const evp_cipher_st *cipher2 = EVP_get_cipherbyname(cipher_str);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,cipher1将始终被设置为有效evp_cipher_st *对象,并且cipher2始终为 null。我还没有找到一个cipher_str产生非 null的实例cipher2

难道我做错了什么?我还应该拨打其他电话才能使其正常工作吗?

nos*_*nos 7

您需要首先初始化 OpenSSL 库。如果您只使用 libcrypto,请调用:

OpenSSL_add_all_algorithms();
Run Code Online (Sandbox Code Playgroud)

有关如何处理其他情况或 openssl 版本的信息,请参阅https://wiki.openssl.org/index.php/Library_Initialization 。

  • 以防万一有人像我一样登陆这里:从 OpenSSL 1.1.0 开始,不再需要它了。 (2认同)