开始使用OpenSSL [英] Starting to use OpenSSL
问题描述
我想在我的跨平台程序中使用SSL.我决定使用OpenSSL.
I want to use SSL in my cross platform program. I decided to use OpenSSL.
我已经安装了OpenSSL,这时我正在浏览代码和文档,试图弄清楚如何使用该库.
I have OpenSSL installed, and at this point I am looking through the code and documentation trying to figure out how to use the library.
您是否有任何资源,简单的程序或教程可以帮助我逐步将OpenSSL与我的程序集成在一起?
Do you have any resources or simple programs or tutorials that will walk me through integrating OpenSSL with my program?
推荐答案
非常粗略的指南是:
- 使用
SSL_CTX_new()
创建新的SSL_CTX
; - (仅服务器)使用
- (仅服务器)使用
SSL_CTX_use_PrivateKey_file()
; - 建立网络连接;
- 使用
SSL_new()
创建新的SSL
- 使用
SSL
的文件描述符设置为网络连接的文件描述符. c7> ; - (仅限客户端)致电
SSL_connect()
; - (仅限服务器)调用
SSL_accept()
.
- Create a new
SSL_CTX
withSSL_CTX_new()
; - (server only) Load the certificate with
SSL_CTX_use_certificate_file()
; - (server only) Load the private key with
SSL_CTX_use_PrivateKey_file()
; - Establish the network connection;
- Create a new
SSL
withSSL_new()
; - Set the file descriptor of the
SSL
to that of your network connection withSSL_set_fd()
; - (client only) Call
SSL_connect()
; - (server only) Call
SSL_accept()
.
此后使用 SSL_read()
和 SSL_shutdown()
.可以重复使用SSL_CTX
来为许多同时进行的会话创建SSL
对象.
Thereafter use SSL_read()
and SSL_write()
to read and write from the connection, and finish with SSL_shutdown()
. The SSL_CTX
can be re-used to create SSL
objects for many simultaneous sessions.
这篇关于开始使用OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!