QCryptographicHash 类

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

头: #include <QCryptographicHash>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

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

公共类型

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

公共函数

QCryptographicHash (QCryptographicHash::Algorithm method )
QCryptographicHash (QCryptographicHash && other )
~QCryptographicHash ()
void addData (QByteArrayView bytes )
bool addData (QIODevice * device )
QCryptographicHash::Algorithm algorithm () const
void reset ()
QByteArray result () const
QByteArrayView resultView () const
void swap (QCryptographicHash & other )
QCryptographicHash & operator= (QCryptographicHash && other )

静态公共成员

QByteArray hash (QByteArrayView data , QCryptographicHash::Algorithm method )
int hashLength (QCryptographicHash::Algorithm method )
bool supportsAlgorithm (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::Blake2b_160 15 Generate a BLAKE2b-160 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2b_256 16 Generate a BLAKE2b-256 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2b_384 17 Generate a BLAKE2b-384 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2b_512 18 Generate a BLAKE2b-512 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2s_128 19 Generate a BLAKE2s-128 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2s_160 20 Generate a BLAKE2s-160 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2s_224 21 Generate a BLAKE2s-224 hash sum. Introduced in Qt 6.0
QCryptographicHash::Blake2s_256 22 Generate a BLAKE2s-256 hash sum. Introduced in Qt 6.0

成员函数文档编制

[explicit] QCryptographicHash:: QCryptographicHash ( QCryptographicHash::Algorithm method )

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

[since 6.5] QCryptographicHash:: QCryptographicHash ( QCryptographicHash && other )

Move-constructs a new QCryptographicHash from other .

注意: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

该函数在 Qt 6.5 引入。

QCryptographicHash:: ~QCryptographicHash ()

销毁对象。

void QCryptographicHash:: addData ( QByteArrayView bytes )

Adds the characters in bytes to the cryptographic hash.

注意: In Qt versions prior to 6.3, this function took QByteArray , not QByteArrayView .

bool QCryptographicHash:: addData ( QIODevice * device )

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

[since 6.5] QCryptographicHash::Algorithm QCryptographicHash:: algorithm () const

Returns the algorithm used to generate the cryptographic hash.

该函数在 Qt 6.5 引入。

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

返回哈希为 data 使用 method .

注意: In Qt versions prior to 6.3, this function took QByteArray , not QByteArrayView .

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

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

void QCryptographicHash:: reset ()

重置对象。

QByteArray QCryptographicHash:: result () const

返回最终的哈希值。

另请参阅 resultView () 和 QByteArray::toHex ().

[since 6.3] QByteArrayView QCryptographicHash:: resultView () const

返回最终的哈希值。

Note that the returned view remains valid only as long as the QCryptographicHash object is not modified by other means.

该函数在 Qt 6.3 引入。

另请参阅 result ().

[static, since 6.5] bool QCryptographicHash:: supportsAlgorithm ( QCryptographicHash::Algorithm method )

Returns whether the selected algorithm method is supported and if result () will return a value when the method 被使用。

注意: OpenSSL will be responsible for providing this information when used as a provider, otherwise true will be returned as the non-OpenSSL implementation doesn't have any restrictions. We return false if we fail to query OpenSSL.

该函数在 Qt 6.5 引入。

[since 6.5] void QCryptographicHash:: swap ( QCryptographicHash & other )

Swaps cryptographic hash other with this cryptographic hash. This operation is very fast and never fails.

该函数在 Qt 6.5 引入。

[since 6.5] QCryptographicHash &QCryptographicHash:: operator= ( QCryptographicHash && other )

移动赋值 other 到此 QCryptographicHash 实例。

注意: The moved-from object other is placed in a partially-formed state, in which the only valid operations are destruction and assignment of a new value.

该函数在 Qt 6.5 引入。