我正在开发Windows 8 64位操作系统上的Qt应用程序。我遇到了这种奇怪的情况,其中MD5消息摘要只有4个字符长(仅= 32位)。除了这个特殊的输入,我得到16个字符(= 128位)的消息摘要字符串。MD5摘要被表示为QString时被截断
MD5 message digest should be fixed length
我的代码片段
qDebug()<<"Case 1:=> ";
message1="HYQPTPORKTWKJSVIVXHS1.130hello world!";
input.append(message1);
output=QCryptographicHash::hash(input,QCryptographicHash::Md5);
QString digest1(QString(output).toAscii());
qDebug()<<"md5 string: "<<digest1;
qDebug()<<"length :"<<digest1.length();
qDebug()<<"Case 2:=>";
input=""; // clears previous input
message2="HYQPTPORKTWKJSVIVXHS1.131hello world!"; // put anything else than message1
input.append(message2);
output=QCryptographicHash::hash(input,QCryptographicHash::Md5);
QString digest2(QString(output).toAscii());
qDebug()<<"md5 string: "<<digest2;
qDebug()<<"length :"<<digest2.length();
输出
Case 1:=>
md5 string: ")QÄ"
length : 4 // here I'm expecting 16
Case 2:=>
md5 string: "X,öéö< Ú4Îu"
length : 16
难道I D出错了吗?
最好的方式来看待这样的事情是库代码是正确的,并且meitake是在使用它的方式。 – zaph