C++实现AES加密
本人开发环境:vs2022,平台工具集vs2015(v140)
要做到的如下图
需要下载Cryptopp
库 https://github.com/weidai11/cryptopp
打开默认工程,生成即可,选择cryptlib
项目点击生成,产生头文件和lib文件
实现代码:
#include <Cryptopp/aes.h>
#include <Cryptopp/filters.h>
#include <Cryptopp/modes.h>
#include <Cryptopp/base64.h>
using namespace std;
using namespace CryptoPP;
string EncryptUtil::AES_encrypt(const char* key, string& content)
{
string cipher;
try {
ECB_Mode< AES >::Encryption ecb_encription((const unsigned char*)key, 16);
StringSource(content, true,
new StreamTransformationFilter(ecb_encription,
new Base64Encoder(new StringSink(cipher)),
BlockPaddingSchemeDef::PKCS_PADDING));
}
catch (const Exception& e) {
cout << e.what() << endl;
}
return cipher;
}