QT5制作MD5加密校验工具
QString path = QFileDialog::getOpenFileName(this,tr("请选择文件"),"D:/",tr("All file(*)"));
if(path == "")
return ;
得到文件路径后,用只读权限,用文本流获取文本的数据。
QFile MD5_File(path);
MD5_File.open(QIODevice::ReadOnly);
QTextStream put(&MD5_File);
QString linedata =put.readAll();
定义一个字符串,调用QCryptographicHash::hash 哈希算法,就直接得到MD5码了。
QByteArray MD5code ;
MD5code = QCryptographicHash::hash ( linedata.toLatin1(), QCryptographicHash::Md5 );
QString S19md5 = pwdmd5.append(MD5code.toHex());
qDebug() << S19md5;
最后,把MD5码转成十六进制表示出来。
例子:
QString testtext = "Aa123456";
QByteArray MD5code;
MD5code = QCryptographicHash::hash( testtext.toLatin1(),QCryptographicHash::Md5);
QString S19md5 = pwdmd5.append(MD5code.toHex());
qDebug() << S19md5;
"afdd0b4ad2ec172c586e2150770fbf9e"