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

openssl基于ede3的加密和解密

  1. 基于ede3的加密和解密
  2. 当前提供模式有cfb和cbc
  3. 数据长度非向量整数倍
  4. 特别注意当数据长度是非向量证书倍的时候该如何处理数据
  5. openssl 版本
    OpenSSL 1.1.1 11 Sep 2018
  6. 验证结果:
    明文 100:
    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63
    please select :
    1: EVP_des_ede3_ofb
    2: EVP_des_ede3_cbc
    1
    加密结果长度:100
    58 ec 26 8c 73 f3 b7 99 4f d0 bd 41 43 57 e8 62 41 3c a6 9d 5c 94 e2 82 54 50 29 71 8f b5 bd 64 b2 21 b2 71 30 30 25 01 8b ef 46 df 23 e5 4a 95 0a d7 0f 45 2e 1a 03 16 7f 2e 70 64 80 e7 c6 97 85 14 37 59 7f a9 5c 53 f5 59 9a 15 24 89 dc b9 fe c6 57 5a d3 e0 e1 25 34 96 2b 43 74 43 47 7e c8 5f c5 ef
    解密结果长度:100
    00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 38 39 3a 3b 3c 3d 3e 3f 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f 50 51 52 53 54 55 56 57 58 59 5a 5b 5c 5d 5e 5f 60 61 62 63
    test ok!
// 编译:gcc -g test_1.c -o test_1 -L/usr/lib -lssl -lcrypto#include<string.h>#include"openssl/err.h"#include"openssl/evp.h"intmain(){intret,which=1;EVP_CIPHER_CTX*ctx;constEVP_CIPHER*cipher;unsignedcharkey[24],iv[8],in[100],out[108],de[100];inti,len,inl,outl,total=0;for(i=0;i<24;i++){memset(&key[i],i,1);}for(i=0;i<8;i++){memset(&iv[i],i,1);}printf("明文 100:\n");for(i=0;i<100;i++){memset(&in[i],i,1);printf("%02x ",in[i]);}printf("\n");// EVP_CIPHER_CTX_init(ctx);ctx=EVP_CIPHER_CTX_new();printf("please select :\n");printf("1: EVP_des_ede3_ofb\n");printf("2: EVP_des_ede3_cbc\n");scanf("%d",&which);if(which==1)cipher=EVP_des_ede3_ofb();elsecipher=EVP_des_ede3_cbc();ret=EVP_EncryptInit_ex(ctx,cipher,NULL,key,iv);if(ret!=1){printf("EVP_EncryptInit_ex err1!\n");return-1;}inl=50;len=0;EVP_EncryptUpdate(ctx,out+len,&outl,in,inl);len+=outl;EVP_EncryptUpdate(ctx,out+len,&outl,in+50,inl);len+=outl;EVP_EncryptFinal_ex(ctx,out+len,&outl);len+=outl;printf("加密结果长度:%d\n",len);for(i=0;i<len;i++){printf("%02x ",*(out+i));}printf("\n");/* 解密 */EVP_CIPHER_CTX_cleanup(ctx);EVP_CIPHER_CTX_init(ctx);ret=EVP_DecryptInit_ex(ctx,cipher,NULL,key,iv);if(ret!=1){printf("EVP_DecryptInit_ex err1!\n");return-1;}total=0;EVP_DecryptUpdate(ctx,de+total,&outl,out,44);total+=outl;EVP_DecryptUpdate(ctx,de+total,&outl,out+44,len-44);total+=outl;ret=EVP_DecryptFinal_ex(ctx,de+total,&outl);total+=outl;printf("解密结果长度:%d\n",total);for(i=0;i<total;i++){printf("%02x ",*(de+i));}printf("\n");if(ret!=1){EVP_CIPHER_CTX_cleanup(ctx);printf("EVP_DecryptFinal_ex err\n");return-1;}if((total!=100)||(memcmp(de,in,100))){printf("err!\n");return-1;}EVP_CIPHER_CTX_cleanup(ctx);printf("test ok!\n");return0;}
http://www.jsqmd.com/news/855943/

相关文章:

  • SigmaStudio和A2B软件安装避坑大全:Win10/Win11系统关联DLL与插件配置一步到位
  • 终极指南:如何用VS Code和Markdown快速制作专业演示文稿
  • 告别云端API费用:用llama.cpp的server功能搭建你的私有化大模型服务
  • ESP8266刷机翻车实录:从固件版本选择到串口驱动安装,这些坑我都替你踩过了
  • TDK高可靠性MLCC五大系列解析:从材料创新到严苛应用选型指南
  • 阿钱¥¥¥openssl sm3 hmac api使用和命令行验证
  • 解析日本工程塑料厂家代理新日铁住金产品的核心价值与
  • 从零到一:AI 3D建模革命,5分钟让图片“活“起来的完整实战指南
  • Gev部署运维指南:生产环境最佳实践与性能监控
  • 留学生面试遇“压力面试”?2026海外职场高压应对实战指南
  • 告别手动清理!用TypeScript给你的LocalStorage加个自动过期功能(附完整源码)
  • CANape数据处理实战:MF4文件分析、导出Excel与A2L文件替换全流程解析
  • linux文件基本操作作业(含文件基本操作的重点知识内容及截图)
  • 从选题到终稿:okbiye 如何用一套流程,解决本科毕业论文 90% 的痛点
  • 从‘浴盆曲线’到加速测试:拆解企业级SSD如何做到MTBF 200万小时
  • HarmonyOS 6(API 23)实战
  • 2026年4月技术好的安检仪源头厂家口碑推荐,金属探测门/安检设备/安检机/智能安检/安检仪,安检仪源头厂家推荐分析 - 品牌推荐师
  • Angular-dragdrop与Bootstrap集成:构建响应式拖放界面的完美方案
  • ScrollMonitor:JavaScript滚动监控库的完整指南 - 如何高效监听元素进入视口
  • 想让LQR控制器精准跟踪轨迹?别急着调参,先搞懂‘增广系统’这个核心概念
  • C++继承详细介绍
  • 别再被Linux的free命令骗了!手把手教你读懂‘可用内存’available的真实含义
  • 2026年热门的地源热泵节能效果/地源热泵节能率/车间地源热泵施工品牌公司推荐 - 品牌宣传支持者
  • CANN/asc-devkit Tiling模板参数选择宏
  • Linux 软件包管理(含上机实例)
  • WS2812B灯条颜色错乱:从原理到实战的完整排查与解决方案
  • 告别邮件测试烦恼:MailHog一站式解决方案让开发调试更高效
  • HarmonyOS 6(API 23)实战1
  • 为什么你需要一个完整的Unity历史版本下载库?开发者必备的版本管理解决方案
  • 面试官:你知道的限流算法有哪些?