谁对Crypt++比较熟的,请教一下?

wlltwllt 2015-11-08 04:13:39
用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算法不能进行循环多轮加密吗?
...全文
584 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复

9,506

社区成员

发帖
与我相关
我的任务
社区描述
Windows专区 安全技术/病毒
社区管理员
  • 安全技术/病毒社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧