我有下面的代码来加密和解密Qt中的botan文件。加密大文件时会花费大量时间,我想在加密/解密大文件时获取处理的字节数。可能吗?
void AES::Encrypt(SymmetricKey key, InitializationVector iv, string inFilename, string outFilename)
{
std::ifstream in(inFilename.c_str(),std::ios::binary);
std::ofstream out(outFilename.c_str(),std::ios::binary);
Pipe pipe(get_cipher("AES-256/CBC", key, iv,ENCRYPTION),new DataSink_Stream(out));
pipe.start_msg();
in >> pipe;
pipe.end_msg();
out.flush();
out.close();
in.close();
qDebug() << "Encrypted!";
}
void AES::Decrypt(SymmetricKey key, InitializationVector iv, string inFilename, string outFilename)
{
std::ifstream in(inFilename.c_str(),std::ios::binary);
std::ofstream out(outFilename.c_str(),std::ios::binary);
Pipe pipe(get_cipher("AES-256/CBC", key, iv,DECRYPTION),new DataSink_Stream(out));
pipe.start_msg();
in >> pipe;
pipe.end_msg();
out.flush();
out.close();
in.close();
qDebug() << "Decrypted!";
}
如果您查看有关管道/过滤器机制的 Botan 文档,就会发现其中有关于处理大文件和限制使用内存的讨论。在该部分的末尾,是一个代码片段,它显示了使用有界缓冲区处理大文件。通过在那里添加一些代码,我认为您将能够防止加密操作耗尽内存,并能够从该循环中触发Qt进度信号。