// 计算文件的 MD5 值
static inline QString calculateFileMd5(const QString& filePath) {
QFile file(filePath);
if (!file.open(QIODevice::ReadOnly)) {
qDebug() << "Cannot open file:" << filePath;
return QString();
}
QCryptographicHash hash(QCryptographicHash::Md5);
if (!hash.addData(&file)) {
qDebug() << "Cannot read file:" << filePath;
return QString();
}
QByteArray md5 = hash.result();
return md5.toHex().toUpper();
}
// 校验两个 MD5 值是否匹配
static bool verifyMd5Match(const QString& md5_1, const QString& md5_2) {
return md5_1 == md5_2;
}
分享一下文件md5计算和校验源代码