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. QCryptographicHash::Md5 VS md5sum [Solved]
Forum Updated to NodeBB v4.3 + New Features

QCryptographicHash::Md5 VS md5sum [Solved]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.3k Views 1 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I need to generate an MD5 sum in Qt 5.

    This is my example code:
    @
    QCryptographicHash md5_generator(QCryptographicHash::Md5);
    md5_generator.addData("123456789");
    qDebug() << md5_generator.result().toHex();
    @
    and I get:
    @
    25f9e794323b453885f5181f1b624d0b
    @

    Now I create a file with the same content:
    @
    123456789
    @
    and I try md5sum linux command I get:
    @
    $ md5sum test
    b2cfa4183267af678ea06c7407d4d6d8
    @

    Where is the problem?

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      I checked it with another tool and it's the same as Qt result.
      Are you sure you didn't put a newline at the end of the file? It will also count as content.

      1 Reply Last reply
      0
      • sierdzioS Offline
        sierdzioS Offline
        sierdzio
        Moderators
        wrote on last edited by
        #3

        Maybe the Linux tool also takes some file metadata (encoding, maybe BOM is present?) into account? In your Qt code you pass only the raw data. For Linux, you pass a whole file.

        (Z(:^

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          I just checked for a string "123456789\n" and the checksum is indeed b2cfa4183267af678ea06c7407d4d6d8
          So just fix your file.

          1 Reply Last reply
          0
          • L Offline
            L Offline
            luca
            wrote on last edited by
            #5

            Thanks for the answers!

            The file was created with "vi" and I didn't put new line at the end of the text.

            There probably is in the file a kind of EOF that I don't see.

            Thanks again!

            1 Reply Last reply
            0
            • C Offline
              C Offline
              ChrisW67
              wrote on last edited by
              #6

              By default vi will ensure the last line of the file has a line feed. Your current file will be 10 bytes (11 on Windows). If you are actually using vim, instead of generic vi, you can turn that off:
              http://vim.wikia.com/wiki/File_format#Terminator_after_last_line

              To create your test file without the line feed (UNIX):
              @
              $ echo -n '123456789' > test.txt
              $ ls -l test.txt
              -rw-r--r-- 1 chrisw users 9 Apr 4 11:29 test.txt
              @

              1 Reply Last reply
              0
              • L Offline
                L Offline
                luca
                wrote on last edited by
                #7

                Very interesting.
                Now it's more clear.

                Thanks!

                1 Reply Last reply
                0

                • Login

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