Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-109390

QCryptographicHash::hash return value type is QByteArray , but the value is truncated because '/0' termination rules

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • P2: Important
    • None
    • 5.15.2
    • Core: Other
    • None
    • Windows

    Description

      QCryptographicHash::hash will return a QByteArray value. But when the value contains 0x00, the value is invalid because QByteArray::data will return data with ‘/0’ termination。And I can't get the complete value by someway at this time.

       

      code(line196-214):

      https://github.com/moonlight-stream/moonlight-qt/blob/master/app/backend/nvpairingmanager.cpp

      the aesKey value is invalid sometimes because QCryptographicHash::hash return value contains 0x00.

       

      PS:

      It maybe need to change class QCryptographicHash member: d->result construction.

      Use QByteArray::QByteArray(const char *data, int size = -1)

       

       

      //C++
      #include <QCoreApplication>
      #include <QCryptographicHash>
      #include <QDebug>
      
      int main(int argc, char *argv[])
      {
          QCoreApplication a(argc, argv);
      
          QByteArray b = QByteArray::fromHex("b8d626cbe3218160752f8be86bf570ec");
          QString c = "1234";
          QByteArray to_hash_data;
          to_hash_data = QByteArray().append(b).append(c.toLatin1());
          qInfo() << to_hash_data.toHex();
          QByteArray aesKey = QCryptographicHash::hash(to_hash_data, QCryptographicHash::Sha256).constData();
          qInfo() << "aesKey data size:" << strlen(aesKey.data()); // output: aesKey data size:1
      
          return a.exec();
      }
      

       

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            dreamychi PanHe
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes