EVP_get_cipherbyname 总是 returns 空

EVP_get_cipherbyname always returns null

我在 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);

在上面的代码中,cipher1 将始终设置为有效的 evp_cipher_st * 对象,而 cipher2 将始终为 null。我还没有找到生成非空 cipher2.

的单个 cipher_str 实例

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

您需要先初始化OpenSSL库。如果你只是使用 libcrypto, 通话:

OpenSSL_add_all_algorithms();

其他情况或openssl版本请参考https://wiki.openssl.org/index.php/Library_Initialization