代碼:
#include <stdio.h>
#include <openssl/rand.h>
#include <iostream>
#include <time.h>using namespace std;int main()
{cout << "first openssl code!" << endl;time_t t = time(0); //以時間作為隨機數種子unsigned char buf[16] = { 0 };int re = RAND_bytes(buf, sizeof(buf));for (int i = 0; i < sizeof(buf); i++){cout << "[" <<(int) buf[i] << "]";}getchar();return 0;
}
makefile:
first_openssl:first_openssl.cppg++ $^ -o $@ -I/usr/local/include -L/usr/local/lib -lcrypto
注意:
1.linux下編譯可能報錯
./first_openssl: error while loading shared libraries: libcrypto.so.3: cannot open shared object file: No such file or directory
解決辦法:
cp libcrypto.so /usr/lib
sudo ldconfig
2.makefile中
$@是目標文件
$^是依賴項
版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。
工作时间:8:00-18:00
客服电话
电子邮件
admin@qq.com
扫码二维码
获取最新动态