2014年03月06日 星期四 09:50
QCryptographicHash模块提供了计算加密哈希值的一些算法,包括MD5,SHA-1,SHA-256等,可以分段提供源数据,也可以将源数据封装为一个QIODevice,然后传入给QCryptographicHash。
The QCryptographicHash class provides a way to generate cryptographic hashes.
QCryptographicHash can be used to generate cryptographic hashes of binary or text data.
Currently MD4, MD5, SHA-1, SHA-224, SHA-256, SHA-384, and SHA-512 are supported.
示例代码如下:
#include <QCoreApplication>
#include <QtCore>
int main(int argc, char *argv[])
{
QCoreApplication a(argc, argv);
QFile hf("C:/Qt/Projects/016_QCryptographicHash/main.cpp");
hf.open(QIODevice::ReadOnly);
QCryptographicHash hs(QCryptographicHash::Md5);
hs.addData(&hf);
auto result=hs.result();
qDebug() << result.toHex();
hs.reset();
return a.exec();
}
参考资料:
Zeuux © 2025
京ICP备05028076号