我正在開發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