I'm trying to decrypt a string which is ciphered using AES in CBC_Mode. I see correct data in the result but it is polluted by padding bytes. My first attempt was to use a Redirector as suggested in this thread:
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&)
{ }
}
But I still get these padding bytes. What am I doing wrong? Can someone help me please?
OK, finally I found my foolish mistake. It has nothing to do with padding bytes. The reason for having those extra bytes in my decryption result is simply that StringSource appends resulting bytes to the destination. I forgot to clear my destination variable and so it grew on...