【问题标题】:Decryption of a std::string has extra padding bytes?std::string 的解密有额外的填充字节吗?
【发布时间】:2017-09-23 17:37:00
【问题描述】:

我正在尝试解密在 CBC_Mode 中使用 AES 加密的字符串。我在结果中看到了正确的数据,但它被填充字节污染了。 我的第一次尝试是按照this 线程中的建议使用重定向器:

std::string result_;
CryptoPP::CBC_Mode<CryptoPP::AES>::Decryption decrypt_;
...

void decrypt(std::string cipheredText)
{
    try
    {
        CryptoPP::MeterFilter meter(new CryptoPP::StringSink(result_));

        CryptoPP::StringSource pipeline(
            cipheredText,
            true,
            new CryptoPP::StreamTransformationFilter(
                decrypt_,
                new CryptoPP::Redirector(meter),
                CryptoPP::StreamTransformationFilter::PKCS_PADDING));
    }
    catch (CryptoPP::Exception&)
    { }
}

但我仍然得到这些填充字节。我究竟做错了什么?有人可以帮帮我吗?

【问题讨论】:

    标签: c++ aes crypto++ cbc-mode


    【解决方案1】:

    好的,我终于发现了我的愚蠢错误。它与填充字节无关。在我的解密结果中包含这些额外字节的原因很简单 StringSource 将结果字节附加到目标。我忘了清除我的目标变量,所以它继续增长......

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2018-03-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多