【发布时间】:2016-07-01 08:22:08
【问题描述】:
我正在 Windows 8 64 位操作系统上开发 Qt 应用程序。我遇到过这种奇怪的情况,其中 MD5 消息摘要只有 4 个字符长(仅 = 32 位。)。除了这个特殊的输入,我得到 16 个字符(=128 位)的消息摘要字符串。
MD5 message digest should be fixed length
我的代码 sn-p
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
我做错了吗?
【问题讨论】:
-
查看此类内容的最佳方式是库代码是正确的,而且明武是在使用它的方式。