【问题标题】:How to get encryption/decryption progress when encrypt big files with botan in Qt在Qt中使用botan加密大文件时如何获得加密/解密进度
【发布时间】:2012-12-08 13:28:35
【问题描述】:

我有下面的代码在 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!";
}

【问题讨论】:

    标签: c++ qt botan


    【解决方案1】:

    如果您查看有关 Pipe/Filter Mechanisms 的 Botan 文档,就会发现有关处理大文件和限制内存使用的讨论。在该部分的末尾,是一个代码 sn-p,它显示了使用有界缓冲区处理大文件。通过在此处添加一些代码,我认为您将能够防止加密操作耗尽内存以及能够从该循环中触发 Qt 进度信号。

    【讨论】:

    • 谢谢,你的回答很有帮助
    猜你喜欢
    • 2018-12-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 2012-03-03
    相关资源
    最近更新 更多