PDA

View Full Version : QCryptographicHash Question



tntcoda
21st October 2008, 02:08
Hi,

Given the following code:



QByteArray data_to_hash = "test_data";
QCryptographicHash hash(QCryptographicHash::Sha1);

hash.addData(data_to_hash);
qDebug(hash.result().toHex());


I get a hash of 4f20c649228a94d3cc4d31e9d12ec593e20c0202

However... the sha1sum program gives me the following:
...]$ echo "test_data" | sha1sum
45109238d9ab2fac4e954d1b38dc032cf2de629a

I'm probably being incredibly stupid here, but why don't the hash values match? Does qt do some kind of input conversion behind the scenes, or use a salt or something?

Thanks,

Jack

wysota
21st October 2008, 09:45
Echo adds a newline character at the end of the stream.


$ echo -n "test_data" | sha1sum
4f20c649228a94d3cc4d31e9d12ec593e20c0202

tntcoda
21st October 2008, 10:21
Whoops! Thanks very much for the help :)