Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt4 to Qt5 MD5 Hash Compatibility
Forum Updated to NodeBB v4.3 + New Features

Qt4 to Qt5 MD5 Hash Compatibility

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 5 Posters 446 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    MarkNH
    wrote on last edited by
    #1

    I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.

    Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?

    Christian EhrlicherC C 2 Replies Last reply
    0
    • M Offline
      M Offline
      MarkNH
      wrote on last edited by
      #7

      Just to close this out - problem solved. The issue was not the MD5 hash calculation. It was the fact that Qt4 and Qt5 differ when using this constructor QByteArray ba(QString &); The conversion did not produce the same array - which was used to calculate the hash. This gives the appearance of "working" if the QString is Ascii or straight conversion to Latin1. The problem manifested when the QString was a unicode string for a non-Latin base language!

      Solution: QByteArray ba(QString value.toUtf()) - before calculating/verifying the hash!

      Thanks for all the suggestions!

      1 Reply Last reply
      3
      • M MarkNH

        I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.

        Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #2

        MD5 is a defined hash algorithm which must return the same value no matter what programming language or library you're using. And I'm not aware that Qt4 ships a broken MD5 calculation so you must be doing something wrong.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        M 1 Reply Last reply
        2
        • Christian EhrlicherC Christian Ehrlicher

          MD5 is a defined hash algorithm which must return the same value no matter what programming language or library you're using. And I'm not aware that Qt4 ships a broken MD5 calculation so you must be doing something wrong.

          M Offline
          M Offline
          MarkNH
          wrote on last edited by
          #3

          @Christian-Ehrlicher
          The Qt4 - application - calculates and verifies correctly.
          The Qt5 - application - calculates and verifies correctly...
          The Qt5 app fails the hash that was created by the Qt4 application, and vice versa.

          One other thing I forgot to mention - the Qt4 application is a 32bit application and the Qt5 application is a 64 bit application.

          W 1 Reply Last reply
          0
          • M MarkNH

            @Christian-Ehrlicher
            The Qt4 - application - calculates and verifies correctly.
            The Qt5 - application - calculates and verifies correctly...
            The Qt5 app fails the hash that was created by the Qt4 application, and vice versa.

            One other thing I forgot to mention - the Qt4 application is a 32bit application and the Qt5 application is a 64 bit application.

            W Offline
            W Offline
            wrosecrans
            wrote on last edited by
            #4

            @MarkNH It sounds like you are somehow passing different bytes into the Qt4 vs Qt5 programs. If you run a different md5 implementation like the md5sum command line utility on your file, does it match either of them? The actual MD5 implementation should always give the same result for the exact same input.

            1 Reply Last reply
            2
            • M MarkNH

              I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.

              Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?

              C Offline
              C Offline
              ChrisW67
              wrote on last edited by ChrisW67
              #5

              @MarkNH said in Qt4 to Qt5 MD5 Hash Compatibility:

              Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?

              No, it is 3rd party code that, as @Christian-Ehrlicher points out, is well defined and not in need of functional change. There were some very minor edits that have no resulting functional difference.
              Look for yourself:
              Qt5 version
              Qt4 version

              calculated a MD5 hash on some of the content of a file (emphasis mine)

              If you give the algorithm exactly the same bytes then you will get the same result. If the bytes differ the result differs (with almost perfect certainty), which is correct behaviour.

              Potential problems:

              • You have a different part of the file to start with
              • You have the same bytes from the file but are mishandling them in some way before giving them to the MD5 algorithm. This could occur in any number of ways only you can see, e.g. passing the data through QString and mishandling text encodings.

              Reduce the problem to a minimal program that reproduces the problem and supply that code and your data file if you can.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #6

                Hi,

                Any chances you are using QDataStream to write and load your file ? If that's the case, did you explicitly set the version you used to do the inputs and outputs ?

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  MarkNH
                  wrote on last edited by
                  #7

                  Just to close this out - problem solved. The issue was not the MD5 hash calculation. It was the fact that Qt4 and Qt5 differ when using this constructor QByteArray ba(QString &); The conversion did not produce the same array - which was used to calculate the hash. This gives the appearance of "working" if the QString is Ascii or straight conversion to Latin1. The problem manifested when the QString was a unicode string for a non-Latin base language!

                  Solution: QByteArray ba(QString value.toUtf()) - before calculating/verifying the hash!

                  Thanks for all the suggestions!

                  1 Reply Last reply
                  3
                  • M MarkNH has marked this topic as solved on

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved