View Full Version : Decrypting images to QImage

13th June 2018, 00:46
Hi All,

I've spent a more than a few hours on this so any help appreciated. I have a set of encrypted images using Botan library. What is the best approach to decrypt the images so they can be used to construct a QImage. Obviously decrypting to disk is not feasible for the obvious reason but Botan decrypt returns a QString. I'm struggling to get the Qstring to a QByteArray to use something like QImage::loadFromData(const QByteArray &data, const char *format = nullptr).

A link that sums up what I am trying to achieve in Qt is https://www.codeproject.com/Articles/796587/Using-Encrypted-Files-Without-Decrypting-To-Disk

I am using Qt <= 5.4 series from 5.2 to 5.4. Upgrading from 5.2 to 5.4 should all work OK AFAIU but beyond that I am going to hit the QWebkit to QWebEngine conversion tasks. [Upgrading will take time which is unfortunately limited]. Some new functions were introduced in 5.4 which I think simplified this, not sure.

A last question: Is QWebEngine now all stable across all platforms (at least Win 7+, *nix, OS X Sierra)

Thanks in advance folks!

13th June 2018, 09:44
For more information the botan wrapper I am using has:

* Decrypts a file and returns a bool indicating success
* @param Source The source file
* @param Destination The destination file
bool DecryptFile(QString Source, QString Destination);

* Returns a decrypted string from a Base64 encypted string
* @param Data The string to encypt
QString Decrypt(QString Data);

Thanks in advance!

14th June 2018, 00:35
More code example

BotanWrapper cWrapper;
QFile file("/somePath/testEncrypted.jpg");
QString errMsg;
QFileDevice::FileError err = QFileDevice::NoError;
if (!file.open(QIODevice::ReadOnly)) {
errMsg = file.errorString();
err = file.error();
qDebug() << "Error opening the file";
//Handle issues here
QByteArray encFileArray(file.readAll());
qDebug() << "QByteArray Length is :" << encFileArray.length();
QString decFileString(cWrapper.Decode(QString(encFileArray )));
qDebug() << "image w : h is " << inImage.width() << "px : " << inImage.height() << "px";

This outputs

QByteArray Length is : 3121648
image w : h is 0 px : 0 px