Results 1 to 3 of 3

Thread: Decrypting images to QImage

  1. #1
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Decrypting images to QImage

    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...ypting-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!
    Last edited by UKCitizen1423; 13th June 2018 at 00:54.

  2. #2
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Decrypting images to QImage

    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!

  3. #3
    Join Date
    Apr 2014
    Posts
    12
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Decrypting images to QImage

    More code example

    BotanWrapper cWrapper;
    cWrapper.setPassword("something");
    cWrapper.setSalt("somethingElse");
    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 )));
    inImage.loadFromData(decFileString.toUtf8());
    qDebug() << "image w : h is " << inImage.width() << "px : " << inImage.height() << "px";
    addPixmap(QPixmap::fromImage(inImage));
    file.close();

    This outputs

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

Similar Threads

  1. QImage rotate for tiff images
    By jessiemmichael in forum Qt Programming
    Replies: 3
    Last Post: 18th June 2011, 16:32
  2. Encrypting and decrypting with QCA
    By s.g. in forum Qt Programming
    Replies: 1
    Last Post: 6th December 2009, 21:41
  3. Pass remote (web) images to QImage
    By NicholasSmith in forum Qt Programming
    Replies: 2
    Last Post: 25th August 2009, 23:00
  4. Replies: 4
    Last Post: 27th July 2009, 16:45
  5. Writing Images using QImage from 2D Array
    By kaydknight in forum Qt Programming
    Replies: 1
    Last Post: 29th December 2007, 04:06

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.