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

MFC: 文件加解密(单元测试模块)

背景:

  1. 对敏感配置文件(如 XML 格式的配置文件、用户信息等)进行加密,防止被人以文本形式直接查看。
  2. 软件启动前加载加密的配置或资源文件,运行时再进行解密使用,提高逆向破解门槛。
  3. 在传输 XML 文件(如通过网络发送)前进行加密,保障数据在传输过程中的安全性。
#include <openssl/aes.h>
#include <stdio.h>
#include <stdlib.h>void AESEncrypt(const unsigned char *inputData, size_t dataSize, unsigned char *outputData, const unsigned char *key) {AES_KEY aesKey;AES_set_encrypt_key(key, 256, &aesKey);size_t numBlocks = dataSize / 16;for (size_t i = 0; i < numBlocks; ++i) {AES_ecb_encrypt(inputData + i * 16, outputData + i * 16, &aesKey, AES_ENCRYPT);}
}void AESDecrypt(const unsigned char *inputData, size_t dataSize, unsigned char *outputData, const unsigned char *key) {AES_KEY aesKey;AES_set_decrypt_key(key, 256, &aesKey);size_t numBlocks = dataSize / 16;for (size_t i = 0; i < numBlocks; ++i) {AES_ecb_encrypt(inputData + i * 16, outputData + i * 16, &aesKey, AES_DECRYPT);}
}int main() {unsigned char key[32] = "1234567890abcdef1234567890abcdef";  // 32 字节// Read the XML fileconst char *filePath = "path_to_your_xml_file.xml";FILE *file = fopen(filePath, "rb");if (!file) {perror("File open error");return 1;}fseek(file, 0, SEEK_END);long fileSize = ftell(file);fseek(file, 0, SEEK_SET);unsigned char *originalData = (unsigned char *)malloc(fileSize);fread(originalData, 1, fileSize, file);fclose(file);// Allocate memory for encrypted dataunsigned char *encryptedData = (unsigned char *)malloc(fileSize);AESEncrypt(originalData, fileSize, encryptedData, key);// Write encrypted data back to the filefile = fopen(filePath, "wb");if (!file) {perror("File open error");return 1;}fwrite(encryptedData, 1, fileSize, file);fclose(file);// Clean upfree(originalData);free(encryptedData);return 0;
}

文章转载自:
http://campanology.zzyjnl.cn
http://barterer.zzyjnl.cn
http://bathinette.zzyjnl.cn
http://appetence.zzyjnl.cn
http://boatyard.zzyjnl.cn
http://battik.zzyjnl.cn
http://brindle.zzyjnl.cn
http://advocatory.zzyjnl.cn
http://bewitch.zzyjnl.cn
http://avirulence.zzyjnl.cn
http://agaze.zzyjnl.cn
http://calliper.zzyjnl.cn
http://bradshaw.zzyjnl.cn
http://breadth.zzyjnl.cn
http://blindage.zzyjnl.cn
http://anticipator.zzyjnl.cn
http://backcourt.zzyjnl.cn
http://capreomycin.zzyjnl.cn
http://bled.zzyjnl.cn
http://axoplasm.zzyjnl.cn
http://archiepiscopacy.zzyjnl.cn
http://bobolink.zzyjnl.cn
http://activize.zzyjnl.cn
http://apathetically.zzyjnl.cn
http://antennae.zzyjnl.cn
http://bridge.zzyjnl.cn
http://benniseed.zzyjnl.cn
http://bait.zzyjnl.cn
http://bros.zzyjnl.cn
http://bonn.zzyjnl.cn
http://www.dtcms.com/a/213346.html

相关文章:

  • 理解局部放电分析中的 PRPD 和 PRPS 图
  • 在Spring Boot中实现Kafka动态反序列化:针对多主题的灵活数据处理
  • MySQL数据库零基础入门教程:从安装配置到数据查询全掌握【MySQL系列】
  • 【图像大模型】Stable Diffusion XL:下一代文本到图像生成模型的技术突破与实践指南
  • 用python写节奏大师小游戏
  • 基于大模型的急性腐蚀性胃炎风险预测与诊疗方案研究报告
  • QT5.15 MacOS 打包指南
  • VLLM框架部署Qwen大模型,应该选择哪个qwen3系列的大模型和什么硬件配置?
  • Windows系统如何查看ssh公钥
  • pcdn的发展
  • 论文阅读:2024 arxiv Prompt Injection attack against LLM-integrated Applications
  • java-单列集合list与set。
  • 【SpringBoot】从零开始全面解析Spring IocDI (二)
  • 学习threejs,使用three-spritetext实现黑客帝国数字雨效果
  • C++ list基础概念、list初始化、list赋值操作、list大小操作、list数据插入
  • 云原生架构设计相关原则
  • C++11——智能指针
  • 楼宇自控成智能建筑核心技术,提升节能效率,构筑绿色发展新优势
  • 举例说明MyBatis中逻辑分页的优缺点
  • [onnx 学习记录] 包包含的主要内容
  • python中的时间模块
  • 基于事件驱动型LSTM模型的黄金周收益归因:贸易关税冲击下的5%涨幅量化解析
  • Linux:多线程---初识线程
  • Veeam Backup Replication Console 13 beta 备份 PVE
  • 深入解析Kafka核心参数:buffer_memory、linger_ms与batch_size的优化之道
  • 【基于SpringBoot的图书管理系统】Redis在图书管理系统中的应用:加载和添加图书到Redis,从数据同步到缓存优化
  • 在 Spring Boot 项目中如何合理使用懒加载?
  • Vue 2 混入 (Mixins) 的详细使用指南
  • Vue 3.0中复杂状态如何管理
  • 2025年Google I/O大会上,谷歌展示了一系列旨在提升开发效率与Web体验的全新功能