Qt4 to Qt5 MD5 Hash Compatibility
-
I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.
Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?
-
Just to close this out - problem solved. The issue was not the MD5 hash calculation. It was the fact that Qt4 and Qt5 differ when using this constructor QByteArray ba(QString &); The conversion did not produce the same array - which was used to calculate the hash. This gives the appearance of "working" if the QString is Ascii or straight conversion to Latin1. The problem manifested when the QString was a unicode string for a non-Latin base language!
Solution: QByteArray ba(QString value.toUtf()) - before calculating/verifying the hash!
Thanks for all the suggestions!
-
I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.
Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?
MD5 is a defined hash algorithm which must return the same value no matter what programming language or library you're using. And I'm not aware that Qt4 ships a broken MD5 calculation so you must be doing something wrong.
-
MD5 is a defined hash algorithm which must return the same value no matter what programming language or library you're using. And I'm not aware that Qt4 ships a broken MD5 calculation so you must be doing something wrong.
@Christian-Ehrlicher
The Qt4 - application - calculates and verifies correctly.
The Qt5 - application - calculates and verifies correctly...
The Qt5 app fails the hash that was created by the Qt4 application, and vice versa.One other thing I forgot to mention - the Qt4 application is a 32bit application and the Qt5 application is a 64 bit application.
-
@Christian-Ehrlicher
The Qt4 - application - calculates and verifies correctly.
The Qt5 - application - calculates and verifies correctly...
The Qt5 app fails the hash that was created by the Qt4 application, and vice versa.One other thing I forgot to mention - the Qt4 application is a 32bit application and the Qt5 application is a 64 bit application.
@MarkNH It sounds like you are somehow passing different bytes into the Qt4 vs Qt5 programs. If you run a different md5 implementation like the md5sum command line utility on your file, does it match either of them? The actual MD5 implementation should always give the same result for the exact same input.
-
I have a file that was exported from a Qt4.8.6 system - which calculated a MD5 hash on some of the content of a file. The Hash verifies when the file is opened and verified on a Qt4 application. However the same file when read and verified with Qt5.15.0 the verification fails! Note: When generated on Qt5.15.0 application - the generated hash can be verified in a Qt5.15 application.
Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?
@MarkNH said in Qt4 to Qt5 MD5 Hash Compatibility:
Does the QCryptographicHash::hash( data, QCryptographicHash::MD5) in Qt4 - differ than the one in Qt5?
No, it is 3rd party code that, as @Christian-Ehrlicher points out, is well defined and not in need of functional change. There were some very minor edits that have no resulting functional difference.
Look for yourself:
Qt5 version
Qt4 versioncalculated a MD5 hash on some of the content of a file (emphasis mine)
If you give the algorithm exactly the same bytes then you will get the same result. If the bytes differ the result differs (with almost perfect certainty), which is correct behaviour.
Potential problems:
- You have a different part of the file to start with
- You have the same bytes from the file but are mishandling them in some way before giving them to the MD5 algorithm. This could occur in any number of ways only you can see, e.g. passing the data through QString and mishandling text encodings.
Reduce the problem to a minimal program that reproduces the problem and supply that code and your data file if you can.
-
Hi,
Any chances you are using QDataStream to write and load your file ? If that's the case, did you explicitly set the version you used to do the inputs and outputs ?
-
Just to close this out - problem solved. The issue was not the MD5 hash calculation. It was the fact that Qt4 and Qt5 differ when using this constructor QByteArray ba(QString &); The conversion did not produce the same array - which was used to calculate the hash. This gives the appearance of "working" if the QString is Ascii or straight conversion to Latin1. The problem manifested when the QString was a unicode string for a non-Latin base language!
Solution: QByteArray ba(QString value.toUtf()) - before calculating/verifying the hash!
Thanks for all the suggestions!
-