共有类型
枚举QCryptographicHash::Algorithm:
QCryptographicHash::Md4 0 生成一个MD4散列
QCryptographicHash::Md5 1 生成一个MD5散列
QCryptographicHash::Sha1 2 生成一个SHA-1散列
QCryptographicHash::Sha224 3 生成一个SHA-224散列(SHA-2)
QCryptographicHash::Sha256 4 生成一个SHA-256散列(SHA-2)
QCryptographicHash::Sha384 5 生成一个SHA-384散列(SHA-2)
QCryptographicHash::Sha512 6 生成一个SHA-512散列(SHA-2)
QCryptographicHash::Sha3_224 7 生成一个SHA3-224散列
QCryptographicHash::Sha3_256 8 生成一个SHA3-256散列
QCryptographicHash::Sha3_384 9 生成一个SHA3-384散列
QCryptographicHash::Sha3_512 10 生成一个SHA3-512散列
QString MakeMd5(const QString &sourceFilePath)
{
QFile sourceFile(sourceFilePath);
qint64 fileSize = sourceFile.size();
const qint64 bufferSize = 1024*10;
if (sourceFile.open(QIODevice::ReadOnly)) {
char buffer[bufferSize];
int bytesRead;
int readSize = qMin(fileSize, bufferSize);
QCryptographicHash hash(QCryptographicHash::Md5);
while (readSize > 0 && (bytesRead = sourceFile.read(buffer, readSize)) > 0) {
fileSize -= bytesRead;
hash.addData(buffer, bytesRead);
readSize = qMin(fileSize, bufferSize);
}
sourceFile.close();
return QString(hash.result().toHex());
}
return QString();
}