openssl編譯,C++安全方向openssl(一):1.2 Linux下編譯openssl3.0并編寫測試項目

 2023-10-05 阅读 22 评论 0

摘要:代碼: #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); //以時間作為隨機數種子

在這里插入圖片描述
代碼:

#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中
$@是目標文件
$^是依賴項

版权声明:本站所有资料均为网友推荐收集整理而来,仅供学习和研究交流使用。

原文链接:https://hbdhgg.com/3/114383.html

发表评论:

本站为非赢利网站,部分文章来源或改编自互联网及其他公众平台,主要目的在于分享信息,版权归原作者所有,内容仅供读者参考,如有侵权请联系我们删除!

Copyright © 2022 匯編語言學習筆記 Inc. 保留所有权利。

底部版权信息