QCryptographicHash 类

QCryptographicHash 类提供生成加密哈希的办法。 更多...

头: #include <QCryptographicHash>
qmake: QT += core
Since: Qt 4.3

该类在 Qt 4.3 引入。

注意: 此类的所有函数 可重入 .

公共类型

enum Algorithm { Md4, Md5, Sha1, Sha224, Sha256, …, Keccak_512 }

公共函数

QCryptographicHash (QCryptographicHash::Algorithm method )
~QCryptographicHash ()
void addData (const char * data , int length )
void addData (const QByteArray & data )
bool addData (QIODevice * device )
void reset ()
QByteArray result () const

静态公共成员

QByteArray hash (const QByteArray & data , QCryptographicHash::Algorithm method )
int hashLength (QCryptographicHash::Algorithm method )

详细描述

QCryptographicHash 可用于生成二进制 (或文本数据) 的加密哈希。

参考文档编制中 QCryptographicHash::Algorithm 枚举,支持的算法列表。

成员类型文档编制

enum QCryptographicHash:: Algorithm

注意: In Qt versions before 5.9, when asked to generate a SHA3 hash sum, QCryptographicHash actually calculated Keccak. If you need compatibility with SHA-3 hashes produced by those versions of Qt, use the Keccak_ enumerators. Alternatively, if source compatibility is required, define the macro QT_SHA3_KECCAK_COMPAT .

常量 描述
QCryptographicHash::Md4 0 生成 MD4 哈希和
QCryptographicHash::Md5 1 生成 MD5 哈希和
QCryptographicHash::Sha1 2 生成 SHA-1 哈希和
QCryptographicHash::Sha224 3 生成 SHA-224 哈希和 (SHA-2)。在 Qt 5.0 引入
QCryptographicHash::Sha256 4 Generate an SHA-256 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha384 5 Generate an SHA-384 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha512 6 Generate an SHA-512 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha3_224 RealSha3_224 Generate an SHA3-224 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_256 RealSha3_256 Generate an SHA3-256 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_384 RealSha3_384 Generate an SHA3-384 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_512 RealSha3_512 Generate an SHA3-512 hash sum. Introduced in Qt 5.1
QCryptographicHash::Keccak_224 7 Generate a Keccak-224 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_256 8 Generate a Keccak-256 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_384 9 Generate a Keccak-384 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_512 10 Generate a Keccak-512 hash sum. Introduced in Qt 5.9.2

成员函数文档编制

QCryptographicHash:: QCryptographicHash ( QCryptographicHash::Algorithm method )

构造可用于从数据创建加密哈希的对象,使用 method .

QCryptographicHash:: ~QCryptographicHash ()

销毁对象。

void QCryptographicHash:: addData (const char * data , int length )

Adds the first length chars of data to the cryptographic hash.

void QCryptographicHash:: addData (const QByteArray & data )

此函数重载 addData()。

bool QCryptographicHash:: addData ( QIODevice * device )

读取数据,从打开 QIODevice device 直到它结束并哈希为止。返回 true 若读取是成功的。

该函数在 Qt 5.0 引入。

[static] QByteArray QCryptographicHash:: hash (const QByteArray & data , QCryptographicHash::Algorithm method )

返回哈希为 data 使用 method .

[static] int QCryptographicHash:: hashLength ( QCryptographicHash::Algorithm method )

Returns the size of the output of the selected hash method in bytes.

该函数在 Qt 5.12 引入。

void QCryptographicHash:: reset ()

重置对象。

QByteArray QCryptographicHash:: result () const

返回最终的哈希值。

另请参阅 QByteArray::toHex ().