• Qt中使用OpenSSL


    1、新建测试OpenSSL的工程

    1.1 在源码路径下新建libs和openssl文件夹

    1.2 按照“Windows平台源码编译OpenSSL”编译出OpenSSL动态库

    copy libcrypto-1_1.dl和libssl-1_1.dll到libs文件夹下

    copy openssl-1.1.1k/include目录到openssl文件夹下

    2、配置工程.pro文件

    2.1 添加库引用

    win32: LIBS += -L$$PWD/libs/ -llibcrypto-1_1 -llibssl-1_1
    

      

    2.2 添加头文件路径

    INCLUDEPATH += $$PWD/openssl/include
    

    3、编写代码

    #include <openssl/ssl.h>
    #include <openssl/err.h>
    #include <openssl/opensslv.h>
    #include <openssl/crypto.h>
    
    int main(int argc, char *argv[])
    {
        SSL_library_init();
        SSL_load_error_strings();
        SSL_CTX *ctx = SSL_CTX_new(SSLv23_client_method());
    
        log_info("OPENSSL_VERSION_NUMBER: %X", OPENSSL_VERSION_NUMBER);
        log_info("SSLeay(): %X", SSLeay());
        log_info("SSLeay_version(SSLEAY_VERSION): %X", SSLeay_version(SSLEAY_VERSION));
        log_info("SSLeay_version(SSLEAY_CFLAGS): %X", SSLeay_version(SSLEAY_CFLAGS));
        log_info("SSLeay_version(SSLEAY_BUILT_ON): %X", SSLeay_version(SSLEAY_BUILT_ON));
        log_info("SSLeay_version(SSLEAY_PLATFORM): %X", SSLeay_version(SSLEAY_PLATFORM));
        log_info("SSLeay_version(SSLEAY_DIR): %X", SSLeay_version(SSLEAY_DIR));
    
        return 0;
    }
    

    编译,运行:

    4、故障排查

    error: aggregate 'EVP_CIPHER_CTX ctx' has incomplete type and cannot be defined EVP_CIPHER_CTX ctx;

    原因:使用的OpenSSL版本不支持"EVP_CIPHER_CTX ctx"这种方式;

    解决:EVP_CIPHER_CTX *ctx = EVP_CIPHER_CTX_new()

  • 相关阅读:
    sql函数
    sql日期
    Windows下串口编程
    Libreoffice/Office:禁止首字母自动大写功能
    convert:图片转pdf失败
    LibreOffice/Calc:单元格设置下拉菜单
    Ubuntu:查询计算机软硬件信息
    tar:文件打包归档
    中科大自主招生2018年笔试数学之五
    文件分割与合并
  • 原文地址:https://www.cnblogs.com/rockyching2009/p/14989873.html
Copyright © 2020-2023  润新知