欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

C++使用openssl实现aes加解密,其中加密是string到文件,解密是文件到string,切合项目背景

发布时间:2023/12/13 35 豆豆
生活随笔 收集整理的这篇文章主要介绍了 C++使用openssl实现aes加解密,其中加密是string到文件,解密是文件到string,切合项目背景 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

代码

  • 使用md5对于用户输入的密码进行保护,也使得密码的长度固定
  • crypto_util.h
#pragma once#include <string>namespace hsm{ namespace mgmt{void get_md5_digest(const std::string &data,uint8_t result[16]);void aes_encrypt_to_file(const std::string &file_name,const std::string &password,const std::string &data);std::string aes_decrypt_from_file(const std::string &file_name,const std::string &password);}//namespace mgmt }//namespace hsm
  • crypto_util.c
#include "crypto_util.h"#include <cstring> #include <fstream> #include <memory> #include <sstream>#include <openssl/aes.h> #include <openssl/md5.h>namespace hsm{ namespace mgmt{voi

总结

以上是生活随笔为你收集整理的C++使用openssl实现aes加解密,其中加密是string到文件,解密是文件到string,切合项目背景的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。