How to use OpenSSL in POCO C++ library correctly(如何在 POCO C++ 库中正确使用 OpenSSL)
问题描述
根据POCO助手中的规范:
According to the Specification in POCO assistant:
初始化 NetSSL 库,以及底层的 OpenSSL库,通过调用 Poco::Crypto::OpenSSLInitializer::initialize().应在使用 NetSSL 库中的任何类之前调用.NetSSL 将自动初始化,通过Poco::Crypto::OpenSSLInitializer 实例或类似机制创建 Context 或 SSLManager 实例时.但是,建议调用 initializeSSL()在任何情况下在应用程序启动时.
Initialize the NetSSL library, as well as the underlying OpenSSL libraries, by calling Poco::Crypto::OpenSSLInitializer::initialize(). Should be called before using any class from the NetSSL library. The NetSSL will be initialized automatically, through Poco::Crypto::OpenSSLInitializer instances or similar mechanisms when creating Context or SSLManager instances. However, it is recommended to call initializeSSL() in any case at application startup.
当我想使用 HTTPSClientSession
时,是否必须先构造一个 Application 对象?如何在客户端中使用它?有大佬可以告诉我吗?非常感谢!
When I want to use HTTPSClientSession
,do I have to construct an Application object first?
How can I use it in Client? Any guy can tell me ?Thank you very much!
推荐答案
以Net/samples/httpget为例,我们将httpget/复制为一个新的httpsget目录:
Let's take Net/samples/httpget as an example, let's copy httpget/ as a new httpsget directory:
- 打开 Makefile,将PocoNetSSL"添加到 target_libs
- 将HTTPClientSession"替换为HTTPSClientSession"
- 您需要为 SSL 使用创建 Poco::Net::Context
- replace 'HTTPClientSession session(uri.getHost(), uri.getPort());'有以下两行:
const Context::Ptr context = new Context(Context::CLIENT_USE, "", "", "", Context::VERIFY_NONE, 9, false, "ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH");
HTTPSClientSession session(uri.getHost(), uri.getPort(), context);
总结:
- 将 PocoNetSSL 添加为 lib_depends
- 使用 Poco::Net::Context 和 HTTPSClientSession
这篇关于如何在 POCO C++ 库中正确使用 OpenSSL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 POCO C++ 库中正确使用 OpenSSL


- 静态初始化顺序失败 2022-01-01
- STL 中有 dereference_iterator 吗? 2022-01-01
- C++ 协变模板 2021-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- Stroustrup 的 Simple_window.h 2022-01-01
- 近似搜索的工作原理 2021-01-01
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01