Hello,
I hope to hash a file name to 128bit with md5, which function can I use in Qt?
Thanks!
Printable View
Hello,
I hope to hash a file name to 128bit with md5, which function can I use in Qt?
Thanks!
Use:
Code:
QCryptographicHash::hash
Launch Qt Assistant and write "md5" to the Index-tab, please.
Use :
Code:
QCryptographicHash::hash(str,QCryptographicHash::Md5).toHex().constData();
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
By combining the docs for QCryptographicHash and QString with a splash of QByteArray:you getCode:
QCryptographicHash hash(QCryptographicHash::Md5); hash.addData(fileName.toLatin1()); qDebug() << hash.result().toHex(); qDebug() << QCryptographicHash::hash(fileName.toLatin1(), QCryptographicHash::Md5).toHex();
Feel free to verify the correctness.Code:
"d615b7ea2e9c46cc84125e638e6e16f0" "d615b7ea2e9c46cc84125e638e6e16f0"