Results 1 to 3 of 3

Thread: QCryptographicHash Question

  1. #1
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QCryptographicHash Question

    Hi,

    Given the following code:

    Qt Code:
    1. QByteArray data_to_hash = "test_data";
    2. QCryptographicHash hash(QCryptographicHash::Sha1);
    3.  
    4. hash.addData(data_to_hash);
    5. qDebug(hash.result().toHex());
    To copy to clipboard, switch view to plain text mode 

    I get a hash of 4f20c649228a94d3cc4d31e9d12ec593e20c0202

    However... the sha1sum program gives me the following:
    ...]$ echo "test_data" | sha1sum
    45109238d9ab2fac4e954d1b38dc032cf2de629a


    I'm probably being incredibly stupid here, but why don't the hash values match? Does qt do some kind of input conversion behind the scenes, or use a salt or something?

    Thanks,

    Jack

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QCryptographicHash Question

    Echo adds a newline character at the end of the stream.

    $ echo -n "test_data" | sha1sum
    4f20c649228a94d3cc4d31e9d12ec593e20c0202

  3. #3
    Join Date
    Jun 2008
    Location
    UK
    Posts
    35
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QCryptographicHash Question

    Whoops! Thanks very much for the help

Similar Threads

  1. Useless but curious compiler warning question
    By Raccoon29 in forum General Programming
    Replies: 4
    Last Post: 30th July 2008, 20:46
  2. Exceptions / setjmp/longjmp question
    By Aceman2000 in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2008, 17:14
  3. Access to QSqlTableModel::isDirty Question.
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th April 2007, 17:49
  4. QThread exit()/quit() question
    By TheKedge in forum Qt Programming
    Replies: 1
    Last Post: 28th August 2006, 14:38

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.