2017-04-14 174 views
-1

我有一個簡單的控制檯程序,應該使用來自Crypto ++庫的AES CFB算法加密文件。由於某種原因,它不起作用。編碼部分:使用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應該充滿密文,但它只是仍然充滿了px880x44

我遵循了這個官方教程:https://www.cryptopp.com/wiki/Advanced_Encryption_Standard

+0

[加密與Crypto ++不能正常工作]的可能重複(http://stackoverflow.com/questions/43352882/aes-encryption-with-crypto-not-working) – jww

+0

原諒我的無知...這是怎麼回事比引用的重複? – jww

+0

@jww。他們沒有區別。我做到了,因爲我沒有回答這個問題。 – Serid

回答

3

ProcessDataoutstring,然後instring那麼長。您已切換輸入和輸出參數data & result(大多數API會將輸出參數放在其方法聲明中的最後,所以這可以解釋錯誤)。

+0

非常感謝!這解決了我的問題! – Serid