gpt4 book ai didi

macos - OpenSSL 和 Rand_bytes

转载 作者:行者123 更新时间:2023-12-05 05:26:55 26 4
gpt4 key购买 nike

我的问题是关于通过 GCC 在 Mac 上使用 OpenSSL。

    #include <stdio.h>
#include <openssl/rand.h>

int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}

我有以下代码,我正在尝试使用 GCC 进行编译。这是我在命令行中输入的内容

    gcc -o ossl ossl.c -lcrypto -lssl

但是我收到以下错误。

Undefined symbols for architecture x86_64: "_Rand_bytes", referenced from: _main in cc2hf0Ij.o ld: symbol(s) not found for architecture x86_64 collect2: ld returned 1 exit status

我没有使用 openssl 的经验。为什么我收到 undefined symbols for architecture x86_64

最佳答案

int main()
{
unsigned char key[128];
Rand_bytes(key,128);
return 0;
}

尝试RAND_bytes:

int main()
{
unsigned char key[128];
int rc = RAND_bytes(key,sizeof(key));
if(rc != 1)
/* Handle failure */

...
OPENSSL_cleanse(key,sizeof(key));
return 0;
}

OpenSSL 文档位于 RAND_bytes(3) .

关于macos - OpenSSL 和 Rand_bytes,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23234390/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com