Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Generating a MD5 Hash with Qt

Tags:

md5

qt

I am trying to generate an MD5 hash with Qt. The hash I generate needs to be compatible with other standard MD5 hashes generated with other languages such as PHP.

This code does not give me the desired results:

QString encodedPass = QString(QCryptographicHash::hash(("myPassword"),QCryptographicHash::Md5)); 

The result is "Þ±SoHu÷Õ?!?¡¯×L" instead of "deb1536f480475f7d593219aa1afd74c". Can someone show me what I am doing wrong?

like image 866
David Avatar asked Mar 31 '11 04:03

David


People also ask

What is MD5 hash generator?

The MD5 hashing algorithm uses a complex mathematical formula to create a hash. It converts data into blocks of specific sizes and manipulates that data a number of times. While this is happening, the algorithm adds a unique value into the calculation and converts the result into a small signature or hash.

Can MD5 generate same hash?

Generally, two files can have the same md5 hash only if their contents are exactly the same. Even a single bit of variation will generate a completely different hash value. There is one caveat, though: An md5 sum is 128 bits (16 bytes).

How long does it take to generate MD5 checksum?

It generally takes 3-4 hours to transfer via NC and then 40 minutes to get the md5sum. The security of the hash is not an issue in this case.


1 Answers

PHP gives it to you in hex, Qt in binary. Convert it to hex using QByteArray::toHex.

QString blah = QString(QCryptographicHash::hash(("myPassword"),QCryptographicHash::Md5).toHex()) 
like image 173
user647445 Avatar answered Sep 20 '22 16:09

user647445