用Crypt ++ 的加密庫進行AES加密,如果采用CFB模式,為什么對一個明文用同一密鑰加密2次的結果變成了初始明文?
// =============================================================================
// Testing Code :
string plain0 = "CFB Mode Test", plain1;
string cipher0, encoded0, recovered0;
string cipher1, encoded1, recovered1;
CFB_Mode< AES >::Encryption e;
AutoSeededRandomPool prng;
// Init random data
SecByteBlock key(AES::DEFAULT_KEYLENGTH);
prng.GenerateBlock( key, key.size() );
byte iv[ AES::BLOCKSIZE ];
prng.GenerateBlock( iv, sizeof(iv) );
// Step 1 Encrypt: user key ,iv to encrypt plain0 ----> cipher0
e.SetKeyWithIV( key, key.size(), iv );
StringSource ss1( plain0, true, new StreamTransformationFilter( e, new StringSink( cipher )) ); StringSource ss2( cipher0, true,new HexEncoder( new StringSink( encoded )) // HexEncoder ); // StringSource
cout << "cipher0 text: " << encoded0 << endl ;
// Use the encrypt result in step 1 to encrypt again
// Use key, iv to encrypt cipher0 to cipher1
plain1 = cipher0;
e.SetKeyWithIV( key, key.size(), iv );
StringSource ss3( plain1, true, new StreamTransformationFilter( e, new StringSink( cipher1 )) );
StringSource ss4( cipher1, true,new HexEncoder( new StringSink( encoded1 )) // HexEncoder );
// StringSource
cout << "cipher1 text: " << encoded1 << endl ;
// =====================================================================
為什么加密后的encoded1 竟然和明文plain0 一字不差?
難道AES演算法不能進行回圈多輪加密嗎?
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/156331.html
標籤:安全技術/病毒
