Learn what Felgo offers to help your business succeed. Start your free evaluation today! Felgo for Your Business

QCryptographicHash Class

The QCryptographicHash class provides a way to generate cryptographic hashes. More...

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

Note: All functions in this class are reentrant.

Public Types

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

Public Functions

QCryptographicHash(QCryptographicHash::Algorithm method)
~QCryptographicHash()
void addData(QByteArrayView bytes)
bool addData(QIODevice *device)
void reset()
QByteArray result() const
QByteArrayView resultView() const

Static Public Members

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

Detailed Description

QCryptographicHash can be used to generate cryptographic hashes of binary or text data.

Refer to the documentation of the QCryptographicHash::Algorithm enum for a list of the supported algorithms.

Member Type Documentation

enum QCryptographicHash::Algorithm

Note: 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.

Constant Value Description
QCryptographicHash::Md4 0 Generate an MD4 hash sum
QCryptographicHash::Md5 1 Generate an MD5 hash sum
QCryptographicHash::Sha1 2 Generate an SHA-1 hash sum
QCryptographicHash::Sha224 3 Generate an SHA-224 hash sum (SHA-2). Introduced in 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

Member Function Documentation

QCryptographicHash::QCryptographicHash(QCryptographicHash::Algorithm method)

Constructs an object that can be used to create a cryptographic hash from data using method.

QCryptographicHash::~QCryptographicHash()

Destroys the object.

void QCryptographicHash::addData(QByteArrayView bytes)

Adds the characters in bytes to the cryptographic hash.

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

[since 5.0] bool QCryptographicHash::addData(QIODevice *device)

Reads the data from the open QIODevice device until it ends and hashes it. Returns true if reading was successful.

This function was introduced in Qt 5.0.

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

Returns the hash of data using method.

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

[static, since 5.12] int QCryptographicHash::hashLength(QCryptographicHash::Algorithm method)

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

This function was introduced in Qt 5.12.

void QCryptographicHash::reset()

Resets the object.

QByteArray QCryptographicHash::result() const

Returns the final hash value.

See also resultView() and QByteArray::toHex().

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

Returns the final hash value.

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

This function was introduced in Qt 6.3.

See also result().

Qt_Technology_Partner_RGB_475 Qt_Service_Partner_RGB_475_padded