问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/15449756/256-bit-rijndael-blocksize