1

I'm decrypting some file with Botan like this:

std::ifstream in (InFilename.c_str(), std::ios::binary);
in.ignore(32);
std::ofstream out (outFilename.c_str(), std::ios::binary);
Pipe pipe(get_cipher("AES-256/CBC",key,iv, DECRYPTION),new DataSink_Stream(out));
try{
pipe.start_msg();
in >> pipe;
pipe.end_msg();
out.flush();
out.close();
in.close();

after i'm receiving signal, that file is decrypted and i'm opening this file like a pdf:

pdf->openFile(outFilename);

Everithing works perfect and fast. But decrypted file located in the same folder, and i want to decrypt file in memory, such as memory mapped file and send it direct to openFile without saving in filesystem. How can i do this? Probably there're a lot of different possibilities with Qt, and Core C++. Thank you!

AntonD
  • 108
  • 12
  • What's your motivation for not saving to the file system? Is it security, performance or some other requirement. Would an alternate solution also be acceptable? – Peter R Feb 16 '14 at 10:46
  • I'm trying to do this for a security reason. The user shouldn't have an access to the encrypted file. I'm tring now to find any possibility to do this in Botan. I mean send file from Pipe to the openFile directly. But it's not so clear for me right now :) – AntonD Feb 16 '14 at 11:05
  • What is the type of `pdf`? Everything depends on what you use to view the pdf! – Kuba hasn't forgotten Monica Feb 16 '14 at 17:23
  • Normally it is const `QString & filePath`. Can i use osftring in this case with some solution? – AntonD Feb 16 '14 at 20:01
  • Or maybe it is possible make an QByteArray? – AntonD Feb 17 '14 at 17:30
  • 1
    You can. I don't know Botan, but the reference shows DataSink_Stream is expecting an std::ostream, not necessarily a std::ofstream. Using something that also inherits of std::ostream should work. Edit: not 100% sure a std::ostream will be enough for the rest of your need, though, and not tested. – Armaghast Feb 18 '14 at 17:24
  • 1
    See http://stackoverflow.com/questions/6493841/convert-stdostream-to-some-array, it shoud do the trick. – Armaghast Feb 18 '14 at 17:30
  • Thank you! I did this, but i'm facing another problem. http://stackoverflow.com/questions/22133523/decrypting-file-in-qt-with-botan-to-ostringstream-instead-of-to-ofstream – AntonD Mar 04 '14 at 12:32

0 Answers0