我正在尝试解密一个在 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&)
{ }
}
但我仍然得到这些填充字节。我究竟做错了什么?有人可以帮帮我吗?
最佳答案
好吧,我终于发现了我的愚蠢错误。它与填充字节无关。在我的解密结果中有这些额外字节的原因很简单 StringSource 将结果字节附加到目标。我忘了清除我的目标变量,所以它继续增长......
关于c++ - std::string 的解密有额外的填充字节?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43632120/