I have a simple console program that should encrypt files with AES CFB algorithm from Crypto++ library. For some reason it is not working. Encoding part:
byte data[16] = { 0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44 };
byte result[16] = { 0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44 };
//Sample key
byte key[16] = { 0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44,
0x88, 0x44, 0x88, 0x44 };
//Generate random Initialization Vector
byte iv[16];
CryptoPP::AutoSeededRandomPool rnd;
rnd.GenerateBlock(iv, CryptoPP::AES::BLOCKSIZE /*16*/);
//Through VisualStudio debug/watch functionality I have found out that
//Crypto++ randomizer works properly so at this point "iv" contains random values
CryptoPP::CFB_Mode<CryptoPP::AES>::Encryption tmp(key, 16, iv, 1);
tmp.ProcessData(data, result, 16);
The problem is that when this code completes result
is supposed to be filled with cyphertext but it just remains filled with px88
and 0x44
.
I was guided by this official tutorial: https://www.cryptopp.com/wiki/Advanced_Encryption_Standard
ProcessData
is outstring
, then instring
then length. You've switched the input and output parameters data
& result
(most API's would put output parameters last in their method declarations, so this could explain the mistake).