visual studio 2019内调用OpenSSL3.0

OpenSSL3.0是在去年升级的,而且还改的很狠,不怎么兼容之前的版本,但是网上能找到的教程又比较早,就很痛苦,好歹摸索出来能跑不报错了,先记一下,可能有多余操作。

1 先安装visual studio 2019和OpenSSL3.0

OpenSSL3.0能正常在控制台进行加解密。
我自己安装时候随手记的内容
https://blog.csdn.net/mandiheyanyu/article/details/122982302

2 新建一个c++项目
3 更改项目属性

VC++ 目录
更改“包含目录”,添加OpenSSL的include路径;
更改“库目录”,添加OpenSSL的lib路径。

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
修改C/C++→常规→附加包含目录
在这里插入图片描述
修改 链接器→常规→附加库目录
在这里插入图片描述
链接器→输入→附加依赖项
加入
libssl.lib;libcrypto.lib;
在这里插入图片描述
将这俩dll拷入到项目中
在这里插入图片描述
这里我实在不清楚到底应该拷到哪里
E:\vcsave\OpenSSLaes\Debug
E:\vcsave\OpenSSLaes\OpenSSLaes
E:\vcsave\OpenSSLaes\OpenSSLaes\Debug
这仨路径下我都放了一份

安装参考的链接
Visual Studio使用openssl库环境搭建
https://blog.csdn.net/qq_19734597/article/details/100563055
关于“在Visual studio 2017中出现:无法打开源文件”的问题!
https://blog.csdn.net/LKR0325/article/details/80144149
其实我不止看了这两份,但是别的我给关掉了,打开过的网页太多了就不想再去找了。

4 运行测试

这份代码也忘了是从哪里找的了,我是真的从网上找不到直接就能跑的完整代码,我也看不懂这是哪种加密,反正它用了openssl的文件,而且能运行不报错

extern "C"
{
#include <openssl/applink.c>
};
#include <stdio.h>
#include <openssl/evp.h>
#include <openssl/bio.h>

int main(void)
{
    EVP_MD_CTX* ctx = NULL;
    EVP_MD* sha256 = NULL;
    const unsigned char msg[] = {
        0x00, 0x01, 0x02, 0x03
    };
    unsigned int len = 0;
    unsigned char* outdigest = NULL;

    /* Create a context for the digest operation */
    ctx = EVP_MD_CTX_new();
    if (ctx == NULL)
        goto err;

    /*
     * Fetch the SHA256 algorithm implementation for doing the digest. We're
     * using the "default" library context here (first NULL parameter), and
     * we're not supplying any particular search criteria for our SHA256
     * implementation (second NULL parameter). Any SHA256 implementation will
     * do.
     */
    sha256 = EVP_MD_fetch(NULL, "SHA256", NULL);
    if (sha256 == NULL)
        goto err;

    /* Initialise the digest operation */
    if (!EVP_DigestInit_ex(ctx, sha256, NULL))
        goto err;

    /*
     * Pass the message to be digested. This can be passed in over multiple
     * EVP_DigestUpdate calls if necessary
     */
    if (!EVP_DigestUpdate(ctx, msg, sizeof(msg)))
        goto err;

    /* Allocate the output buffer */
    outdigest = (unsigned char*)OPENSSL_malloc(EVP_MD_get_size(sha256));
    if (outdigest == NULL)
        goto err;

    /* Now calculate the digest itself */
    if (!EVP_DigestFinal_ex(ctx, outdigest, &len))
        goto err;

    /* Print out the digest result */
    BIO_dump_fp(stdout, outdigest, len);

err:
    /* Clean up all the resources we allocated */
    OPENSSL_free(outdigest);
    EVP_MD_free(sha256);
    EVP_MD_CTX_free(ctx);
}

5 相关教程链接

OpenSSL3.0深入学习
https://blog.csdn.net/include_he/category_11612114.html
openssl3.0 加密算法库编程精要
https://www.cnblogs.com/huowenjie/

  • 2
    点赞
  • 20
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值