使用Crypto ++ / AES CFB加密无效

时间:2017-04-14 21:15:05

标签: c++ encryption aes crypto++

我有一个简单的控制台程序,它应该使用Crypto ++库中的AES CFB算法加密文件。由于某种原因,它无法正常工作。编码部分:

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);

问题在于,当此代码完成时result应填充cyphertext,但它仍然填充px880x44

我受到了这个官方教程的指导:https://www.cryptopp.com/wiki/Advanced_Encryption_Standard

1 个答案:

答案 0 :(得分:3)

ProcessDataoutstring,然后instring为长度。您已切换输入和输出参数data&amp; result(大多数API会将输出参数放在方法声明的最后,所以这可以解释错误)。