这两天在搞android 的调用JNI这块,想把本地的加密搞到.so文件里面,这样反编译的成本会高一些,安全性相对来说高一些。不过研究到一半卡住了,这个领域不太熟悉。
这个错误 "no matching constructor for initialization of 'AES::Decryption'" 通常是指尝试使用 AES::Decryption
类时,提供的参数与该类所期望的构造函数参数不匹配。在 Crypto++ 库中,AES::Decryption
不是一个直接可用的类;
话多说直接上代码,由于之前的学的C语言已经忘得不行了
#include <cryptopp/aes.h>
#include <cryptopp/modes.h>
#include <cryptopp/filters.h>
#include <iostream>
#include <string>
int main()
{
try {
// 密钥和初始化向量(IV)
byte key[CryptoPP::AES::DEFAULT_KEYLENGTH], iv[CryptoPP::AES::BLOCKSIZE];
memset(key, 0x00, CryptoPP::AES::DEFAULT_KEYLENGTH); // 填充密钥
memset(iv, 0x00, CryptoPP::AES::BLOCKSIZE); // 填充IV
// 创建AES加密对象
CryptoPP::CBC_Mode< CryptoPP::AES >::Encryption aesEncryption(key, sizeof(key), iv);
// 原始数据
std::string plaintext = "This is a test message.";
// 缓冲区来存储加密后的数据
std::string ciphertext;
ciphertext.resize(plaintext.length() + aesEncryption.TransformationBlockSize());
// 执行加密
CryptoPP::StringSource ss(plaintext, true,
new CryptoPP::StreamTransformationFilter(aesEncryption,
new CryptoPP::StringSink(ciphertext)
) // StreamTransformationFilter
); // StringSource
// 输出加密后的数据
std::cout << "Encrypted: " << ciphertext << std::endl;
}
catch (const CryptoPP::Exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}
这段代码看起来人畜无害的样子,但是就是跑不起来,就这把等我再研究研究,有了解这块的给个回答,解惑一下。