当前位置: 首页 > news >正文

openssl3.2 - 官方demo学习 - smime - smdec.c

文章目录

    • openssl3.2 - 官方demo学习 - smime - smdec.c
    • 概述
    • 笔记
    • END

openssl3.2 - 官方demo学习 - smime - smdec.c

概述

从pem证书中得到x509*和私钥, 用私钥和证书解密MIME格式的PKCS7密文, 并保存解密后的明文
MIME的数据操作, 都是PKCS7相关的

笔记

/*!
\file smdec.c
\note 
openssl3.2 - 官方demo学习 - smime - smdec.c从pem证书中得到x509*和私钥, 用私钥和证书解密MIME格式的PKCS7密文, 并保存解密后的明文
MIME的数据操作, 都是PKCS7相关的
*//** Copyright 2007-2023 The OpenSSL Project Authors. All Rights Reserved.** Licensed under the Apache License 2.0 (the "License").  You may not use* this file except in compliance with the License.  You can obtain a copy* in the file LICENSE in the source distribution or at* https://www.openssl.org/source/license.html*//* Simple S/MIME signing example */
#include <openssl/pem.h>
#include <openssl/pkcs7.h>
#include <openssl/err.h>#include "my_openSSL_lib.h"int main(int argc, char **argv)
{BIO *_bio_sm = NULL, *_bio_out = NULL, *_bio_pem = NULL;X509 *_x509_pem = NULL;EVP_PKEY *_evp_pkey = NULL;PKCS7 *_pkcs7 = NULL;int ret = EXIT_FAILURE;OpenSSL_add_all_algorithms();ERR_load_crypto_strings();/* Read in recipient certificate and private key */_bio_pem = BIO_new_file("signer.pem", "r");if (!_bio_pem)goto err;_x509_pem = PEM_read_bio_X509(_bio_pem, NULL, 0, NULL);BIO_reset(_bio_pem);_evp_pkey = PEM_read_bio_PrivateKey(_bio_pem, NULL, 0, NULL);if (!_x509_pem || !_evp_pkey)goto err;/* Open content being signed */_bio_sm = BIO_new_file("smencr.txt", "r");if (!_bio_sm)goto err;/* Sign content */_pkcs7 = SMIME_read_PKCS7(_bio_sm, NULL);if (!_pkcs7)goto err;_bio_out = BIO_new_file("encrout.txt", "w");if (!_bio_out)goto err;/* Decrypt S/MIME message */if (!PKCS7_decrypt(_pkcs7, _evp_pkey, _x509_pem, _bio_out, 0))goto err;ret = EXIT_SUCCESS;err:if (ret != EXIT_SUCCESS) {fprintf(stderr, "Error Signing Data\n");ERR_print_errors_fp(stderr);}PKCS7_free(_pkcs7);X509_free(_x509_pem);EVP_PKEY_free(_evp_pkey);BIO_free(_bio_sm);BIO_free(_bio_out);BIO_free(_bio_pem);return ret;}

END

http://www.lryc.cn/news/284067.html

相关文章:

  • vue中改变v-html中包含body标签的样式修改方法
  • 港科夜闻|香港科大团队研发多功能,可重构和抗破坏单线感测器阵列
  • 线程池的简单介绍及使用
  • 使用Python的pygame库实现下雪的效果
  • qt学习:进度条,水平滑动条,垂直滑动条+rgb调试实战
  • C语言中的浮点数存储
  • Pypputeer自动化
  • selenium爬虫爬取当当网书籍信息 | 最新!
  • PTA 7-1 最大子列和问题
  • JAVA实现向Word模板中插入Base64图片和数据信息
  • 深入浅出关于go web的请求路由
  • HarmonyOS—开发环境诊断的功能
  • Golang个人web框架开发-学习流程
  • java面试题(23):Spring Bean如何保证并发安全
  • HarmonyOS【应用服务开发】在模块中添加Ability
  • 根据屏幕尺寸设置html根字号fontSize大小并刷新
  • Flutter 中的 InteractiveViewer:轻松实现交互性
  • UE4 添加按键输入事件 并在蓝图中使用按键输入节点
  • Go 语言命名规范:清晰、简洁、一致
  • 代码随想录训练营第三十期|第十天|栈与队列part01|理论基础● 232.用栈实现队列● 225. 用队列实现栈
  • Backtrader 文档学习-Indicators混合时间框架
  • 网络攻击与检测防御:维护数字安全的关键挑战
  • 使用 Vector 在 Kubernetes 中收集日志
  • ardupilot开发 --- 固件定制(OEM) 篇
  • 爬虫代理IP在电商行业的应用
  • Vue配置语法检查及关闭语法检查的说明
  • 【Linux】yum
  • 安装sftpgo
  • JS-元素尺寸与位置
  • 2024-01-15(SpringMVCMybatis)