View Full Version : Are there functions to make md5 hash
learning_qt
21st July 2009, 10:36
Hello,
I hope to hash a file name to 128bit with md5, which function can I use in Qt?
Thanks!
yogeshgokul
21st July 2009, 10:46
Use:
QCryptographicHash::hash
Launch Qt Assistant and write "md5" to the Index-tab, please.
learning_qt
21st July 2009, 12:28
Use:
QCryptographicHash::hash
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?
yogeshgokul
21st July 2009, 12:59
Use :
QCryptographicHash::hash(str,QCryptographicHash::M d5).toHex().constData();
learning_qt
21st July 2009, 13:58
Use :
QCryptographicHash::hash(str,QCryptographicHash::M d5).toHex().constData();
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.
yogeshgokul
21st July 2009, 14:01
It seems that it opens the file and hashes the binary file.
Kill me :confused::confused::confused:
learning_qt
21st July 2009, 14:08
Kill me :confused::confused::confused:
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
ChrisW67
22nd July 2009, 04:21
By combining the docs for QCryptographicHash and QString with a splash of QByteArray:
QString fileName("/home/ubuntu/pics/pic1.jpg");
QCryptographicHash hash(QCryptographicHash::Md5);
hash.addData(fileName.toLatin1());
qDebug() << hash.result().toHex();
qDebug() << QCryptographicHash::hash(fileName.toLatin1(), QCryptographicHash::Md5).toHex();
you get
"d615b7ea2e9c46cc84125e638e6e16f0"
"d615b7ea2e9c46cc84125e638e6e16f0"
Feel free to verify the correctness.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.