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

openssl3.2 - 官方demo学习 - cms - cms_denc.c

文章目录

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

openssl3.2 - 官方demo学习 - cms - cms_denc.c

概述

将CMS数据结构写入PEM文件, 并将分离后的加密数据单独写到数据文件.

笔记

/*! \file cms_denc.c
* \note openssl3.2 - 官方demo学习 - cms - cms_denc.c
* 将CMS数据结构写入PEM文件
*/ /** Copyright 2008-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*//** S/MIME detached data encrypt example: rarely done but should the need* arise this is an example....*/
#include <openssl/pem.h>
#include <openssl/cms.h>
#include <openssl/err.h>#include "my_openSSL_lib.h"int main(int argc, char **argv)
{BIO *in = NULL, *out = NULL, *tbio = NULL, *dout = NULL;X509 *rcert = NULL;STACK_OF(X509) *recips = NULL;CMS_ContentInfo *cms = NULL;int ret = EXIT_FAILURE;int flags = CMS_STREAM | CMS_DETACHED;OpenSSL_add_all_algorithms();ERR_load_crypto_strings();/* Read in recipient certificate */tbio = BIO_new_file("signer.pem", "r");if (!tbio)goto err;rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL);if (!rcert)goto err;/* Create recipient STACK and add recipient cert to it */recips = sk_X509_new_null();if (!recips || !sk_X509_push(recips, rcert))goto err;/** OSSL_STACK_OF_X509_free() free up recipient STACK and its contents* so set rcert to NULL so it isn't freed up twice.*/rcert = NULL;/* Open content being encrypted */in = BIO_new_file("encr.txt", "r");dout = BIO_new_file("smencr.out", "wb");if (!in)goto err;/* encrypt content */cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags);if (!cms)goto err;out = BIO_new_file("smencr.pem", "w");if (!out)goto err;if (!CMS_final(cms, in, dout, flags))goto err;/* Write out CMS structure without content */if (!PEM_write_bio_CMS(out, cms))goto err;ret = EXIT_SUCCESS;err:if (ret != EXIT_SUCCESS) {fprintf(stderr, "Error Encrypting Data\n");ERR_print_errors_fp(stderr);}CMS_ContentInfo_free(cms);X509_free(rcert);OSSL_STACK_OF_X509_free(recips);BIO_free(in);BIO_free(out);BIO_free(dout);BIO_free(tbio);return ret;
}

END

相关文章:

  • scroll-view在小程序页面里实现滚动,uniapp项目
  • Leading Dimension是什么
  • MyCAT相关问题及答案(2024)
  • 算法通关村第十一关—位运算如何实现压缩存储(黄金)
  • 连接数问题
  • Rust-函数
  • 玩转 Go 生态|Hertz WebSocket 扩展简析
  • 【Databend】多表联结,你不会还没有掌握吧!
  • 12.2内核空间基于SPI总线的OLED驱动
  • 排序算法-希尔排序
  • Oracle 基本命令
  • P1125 [NOIP2008 提高组] 笨小猴——C++
  • Redis面试题14
  • Android Canvas图层saveLayer剪切clipPath原图addCircle绘制对应圆形区域并放大,Kotlin(3)
  • 8. 自定义分页
  • co模块的前端实现
  • Docker 笔记(1):介绍、镜像、容器及其基本操作
  • Gradle 5.0 正式版发布
  • HTTP请求重发
  • Invalidate和postInvalidate的区别
  • Linux编程学习笔记 | Linux多线程学习[2] - 线程的同步
  • PAT A1120
  • PermissionScope Swift4 兼容问题
  • React Transition Group -- Transition 组件
  • Redux系列x:源码分析
  • Sequelize 中文文档 v4 - Getting started - 入门
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • Unix命令
  • vue数据传递--我有特殊的实现技巧
  • weex踩坑之旅第一弹 ~ 搭建具有入口文件的weex脚手架
  • windows下mongoDB的环境配置
  • 对话:中国为什么有前途/ 写给中国的经济学
  • 诡异!React stopPropagation失灵
  • 回顾 Swift 多平台移植进度 #2
  • 前端js -- this指向总结。
  • 如何优雅地使用 Sublime Text
  • 小程序01:wepy框架整合iview webapp UI
  • 小李飞刀:SQL题目刷起来!
  • 移动端解决方案学习记录
  • 再次简单明了总结flex布局,一看就懂...
  • 函数计算新功能-----支持C#函数
  • !!Dom4j 学习笔记
  • #控制台大学课堂点名问题_课堂随机点名
  • (33)STM32——485实验笔记
  • (4)通过调用hadoop的java api实现本地文件上传到hadoop文件系统上
  • (Java实习生)每日10道面试题打卡——JavaWeb篇
  • (附源码)springboot 个人网页的网站 毕业设计031623
  • (简单有案例)前端实现主题切换、动态换肤的两种简单方式
  • (万字长文)Spring的核心知识尽揽其中
  • (转)大道至简,职场上做人做事做管理
  • (转)使用VMware vSphere标准交换机设置网络连接
  • (转载)VS2010/MFC编程入门之三十四(菜单:VS2010菜单资源详解)
  • ./configure,make,make install的作用(转)
  • .NET NPOI导出Excel详解
  • .NET/C# 在代码中测量代码执行耗时的建议(比较系统性能计数器和系统时间)