Hi,
I have found an "invalid PKCS #7 block padding found" exception when usign
LubyRackoff in CBC or ECB mode. Below there is a code snippet that show the 
problem:
----------------------------------------------------------------------------------------------------------
#include <cryptopp/files.h>
#include <cryptopp/filters.h>
#include <cryptopp/osrng.h>
#include <cryptopp/modes.h>
#include <cryptopp/md5.h>
#include <cryptopp/lubyrack.h>

using namespace CryptoPP;
using namespace std;

int main(int argc, char* argv[])
{
    try
    {
        AutoSeededRandomPool rng;
        CBC_Mode<LR<MD5> >::Encryption encoder;
        SecByteBlock sbbKey(encoder.DefaultKeyLength());
        SecByteBlock sbbIV;
        rng.GenerateBlock(sbbKey.begin(), sbbKey.size());
        if (encoder.IsResynchronizable())
        {
            sbbIV.resize(encoder.IVSize());
            rng.GenerateBlock(sbbIV.begin(), sbbIV.size());
            encoder.SetKeyWithIV(sbbKey, sbbKey.size(), sbbIV);
        }
        else
            encoder.SetKey(sbbKey, sbbKey.size());
        FileSource("sample.txt", true, new StreamTransformationFilter(encoder, new 
FileSink("sample.dat")));
        CBC_Mode<LR<MD5> >::Decryption decoder;
        if (decoder.IsResynchronizable())
            decoder.SetKeyWithIV(sbbKey, sbbKey.size(), sbbIV);
        else
            decoder.SetKey(sbbKey, sbbKey.size());
        FileSource("sample.dat", true, new StreamTransformationFilter(decoder, new 
FileSink("sample1.txt")));
    }
    catch (const CryptoPP::Exception &e)
    {
        cout << "\nCryptoPP::Exception caught: " << e.what() << endl;
        return 1;
    }
    catch (const std::exception &e)
    {
        cout << "\nstd::exception caught: " << e.what() << endl;
        return 2;
    }
    return 0;
}
--------------------------------------------------------------------------------------------------------------------------------------
-- 
Gerardo Maiorano

Reply via email to