Question

I have the code below to encrypt and decrypt file with botan in Qt. When encrypt big files it spend a lot of time, and i want to get the number of processed bytes when encrypting/decrypting big files. Is it possible?

   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!";
}
Was it helpful?

Solution

If you look in the Botan documentation about Pipe/Filter Mechanisms, there's a discussion about handling of large files and bounding use of memory. At the end of that section, is a code snippet which shows handling of large files with a bounded buffer. By adding in some code there, I think you'll be able to keep the encryption operation from running out of memory as well as being able to fire Qt progress signals out of that loop.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top