Question

I am trying to port a decryption routine from C# program to C++ using cryptopp, but I have a problem. In the C# program, the key and IV are both 256 bits. So I tried to do something like this:

    char *hash1 = "......";
    std::string hash2;

    CryptoPP::StringSource(hash1, true,new CryptoPP::Base64Decoder(new CryptoPP::StringSink(hash2)));
    CryptoPP::Rijndael::Decryption decryptor(key, 32);
    CryptoPP::CBC_Mode_ExternalCipher::Decryption cbcDecryption( decryptor, iv);
    CryptoPP::StreamTransformationFilter stfDecryptor(cbcDecryption, (new CryptoPP::StringSink( decryptedData ) ));
    stfDecryptor.Put( reinterpret_cast<const unsigned char*>( hash2.c_str() ), hash2.size() );
    stfDecryptor.MessageEnd();

and I am getting

StreamTransformationFilter: ciphertext length is not a multiple of block size.

I tried to pass IV size like this:

    CryptoPP::CBC_Mode<CryptoPP::Rijndael >::Decryption decr;
    decr.SetKeyWithIV(key, 32, iv, 32);

But then I get:

IV length 32 exceeds the maximum of 16.

So, how can I decrypt data, when it was encrypted by IV with length = 32?

Was it helpful?

Solution

Looking at the implementation, the current iterations of crypto++ only support Rijndael with a block size of 16 bytes. As the IV has to be precisely a single block for CBC mode, Rijndael with a 256 bit block size does not seem to be possible.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top