Preamble
I'm working on a project that requires FTP file transfer between two machines, a client and a server. I would like to verify the integrity of the file after transfer by comparing an MD5 checksum generated on the client with one generated on the server. I wrote a command line program using Qt's QCryptographicHash class to do this. Minus error checking, this is the code in its entirety:
Minimal Working Example
#include <QCoreApplication>
#include <QByteArray>
#include <QFile>
#include <QCryptographicHash>
#include <QTextStream>
#include <QStringList>
int main (int argc, char* argv[]) {
QCoreApplication app(argc, argv);
QTextStream cout(stdout, QIODevice::WriteOnly);
QStringList arglist = app.arguments();
QFile file(arglist.at(1));
if(!file.open(QIODevice::ReadOnly)){
/*error checking*/
}
QCryptographicHash cryptoHash(QCryptographicHash::Md5);
while(!file.atEnd()){
cryptoHash.addData(file.readLine());
}
QByteArray hashByteArray = cryptoHash.result();
cout << hashByteArray.toHex() <<endl;
file.close();
return 0;
}
The Problem
On any machine, this code will give a repeatable MD5 hash of any input file. However, different hashes are being generated for the same file when hashed on my client than when hashed on my server. I've been fighting with this awhile, and just can't seem to determine why these hashes aren't matching. My last thought is that it may be an issue related to architecture, as discussed in this SO post. However, in my case, I'm using Qt's implementation of MD5 hashing, so I want to make sure there isn't something else I'm missing before I either abandon Qt's approach or tinker with their source (which is here md5.h and here md5.cpp, BTW).
Machine specifics. Server: CentOS 5.8 64-bit. Client: Win7 64-bit, but on Windows this application was compiled using a 32-bit build of Qt, and is a 32-bit application.
As an aside, I intended on distributing both 32-bit and 64-bit versions of my application. How can I reconcile this issue if it is architecture related and I'm stuck using Qt's source?
EDIT 1: I forgot to mention that I'm transferring all files in Binary mode through FTP and the file sizes do match on the client and the server. I was initially convinced this was a line ending issue, but it doesn't appear to be the case since I'm encountering the issue even in Binary mode FTP transfer.