运行报错No matching constructor for initialization of ‘AES::Encryption‘你们遇到过么?

这两天在搞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;
}

这段代码看起来人畜无害的样子,但是就是跑不起来,就这把等我再研究研究,有了解这块的给个回答,解惑一下。

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

gdk2016

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值