Results 1 to 9 of 9

Thread: Are there functions to make md5 hash

  1. #1
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Are there functions to make md5 hash

    Hello,

    I hope to hash a file name to 128bit with md5, which function can I use in Qt?

    Thanks!

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Are there functions to make md5 hash

    Use:
    Qt Code:
    1. QCryptographicHash::hash
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Are there functions to make md5 hash

    Launch Qt Assistant and write "md5" to the Index-tab, please.
    J-P Nurmi

  4. #4
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Are there functions to make md5 hash

    Quote Originally Posted by yogeshgokul View Post
    Use:
    Qt Code:
    1. QCryptographicHash::hash
    To copy to clipboard, switch view to plain text mode 
    Thanks for your reply!
    After I use this function, it seems that the hash value is binary. I hope to get text hash value with 256 bit long.
    for example,
    cab9941d1056e911ff775acdda43086a

    How can we get it?

  5. #5
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Are there functions to make md5 hash

    Use :
    Qt Code:
    1. QCryptographicHash::hash(str,QCryptographicHash::Md5).toHex().constData();
    To copy to clipboard, switch view to plain text mode 

  6. The following user says thank you to yogeshgokul for this useful post:

    learning_qt (21st July 2009)

  7. #6
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Are there functions to make md5 hash

    Quote Originally Posted by yogeshgokul View Post
    Use :
    Qt Code:
    1. QCryptographicHash::hash(str,QCryptographicHash::Md5).toHex().constData();
    To copy to clipboard, switch view to plain text mode 
    If I just hope to hash a file name like this: /home/ubuntu/pics/pic1.jpg, how can I do it?
    Because when I use the function QCryptographicHash::hash(str,QCryptographicHash::M d5).toHex().constData();
    It seems that it opens the file and hashes the binary file.

  8. #7
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Are there functions to make md5 hash

    Quote Originally Posted by learning_qt View Post
    It seems that it opens the file and hashes the binary file.
    Kill me

  9. #8
    Join Date
    Sep 2008
    Posts
    93
    Thanks
    6
    Thanked 1 Time in 1 Post

    Default Re: Are there functions to make md5 hash

    Quote Originally Posted by yogeshgokul View Post
    Kill me
    This is the result I got with the file name /home/ubuntu/pics/pic1.jpg
    Q┤␋┌┌::▒⎽┐I└▒±␊:├␤␊ ␤▒⎽␤ ┴▒┌┤␊ ␋⎽: °2␌00␊␌8␉°°␉653␍16978627␊␊▒30␌82
    Q┤␋┌┌::▒⎽┐I└▒±␊:├␤␊ °␋┌␊ ┼▒└␊ ␋⎽: "/␤⎺└␊/┬␊┼⎻␊┼±/233.┘⎻±"
    Q┤␋┌┌::▒⎽┐I└▒±␊:├␤␊ °┤┌┌ °␋┌␊ ┼▒└␊ ␋⎽: "°␋┌␊:////␤⎺└␊/┬␊┼⎻␊┼±/233.┘⎻±"
    Q┤␋┌┌::▒⎽┐I└▒±␊:├␤␊ ␤▒⎽␤ ┴▒┌┤␊ ␋⎽: "5æF±ð—›Â ƒÂ¢YÃ*$␉ð"
    Q┤␋┌┌::▒⎽┐I└▒±␊:├␤␊ ␤▒⎽␤ ┴▒┌┤␊ ␋⎽: 35␊646␉1°0979␉81␊2597°␌32▒2462°0

    If removed .jpg from the file name, I could get nice result.
    cab9941d1056e911ff775acdda43086a

  10. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Are there functions to make md5 hash

    By combining the docs for QCryptographicHash and QString with a splash of QByteArray:
    Qt Code:
    1. QString fileName("/home/ubuntu/pics/pic1.jpg");
    2. QCryptographicHash hash(QCryptographicHash::Md5);
    3. hash.addData(fileName.toLatin1());
    4. qDebug() << hash.result().toHex();
    5.  
    6. qDebug() << QCryptographicHash::hash(fileName.toLatin1(), QCryptographicHash::Md5).toHex();
    To copy to clipboard, switch view to plain text mode 
    you get
    Qt Code:
    1. "d615b7ea2e9c46cc84125e638e6e16f0"
    2. "d615b7ea2e9c46cc84125e638e6e16f0"
    To copy to clipboard, switch view to plain text mode 
    Feel free to verify the correctness.
    Last edited by ChrisW67; 22nd July 2009 at 04:28.

Similar Threads

  1. Replies: 12
    Last Post: 14th August 2007, 17:54
  2. Window OS make distclean && qmake && make one line
    By patrik08 in forum General Programming
    Replies: 4
    Last Post: 22nd March 2007, 10:43
  3. Compiling with Qmake/Make
    By VireX in forum Newbie
    Replies: 25
    Last Post: 22nd February 2007, 05:57
  4. Qt/Embedded Installation error during make
    By mahe2310 in forum Installation and Deployment
    Replies: 5
    Last Post: 7th September 2006, 04:05
  5. Qt4.1.4 make errors.
    By impeteperry in forum Installation and Deployment
    Replies: 11
    Last Post: 1st July 2006, 17:27

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.