谁对Crypt++比较熟的,请教一下?
用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算法不能进行循环多轮加密吗?