6.0.0-rc4Source

QMessageAuthenticationCode Class

The QMessageAuthenticationCode class provides a way to generate hash-based message authentication codes. More…

Header#include <QMessageAuthenticationCode>
CMaketarget_link_libraries(app PRIVATE Nt::Core)
ModuleNt Core C++ Classes

List of all members, including inherited members

Public Functions

Static Public Members

Detailed Description

QMessageAuthenticationCode computes an HMAC, as defined by RFC 2104, over the data added with addData(), using a secret key and one of the QCryptographicHash algorithms.

QByteArray mac = QMessageAuthenticationCode::hash("message", "secret", QCryptographicHash::Sha256);

See also QCryptographicHash.

Differences from Qt

The class cannot be copied or moved. It supports the same algorithms as QCryptographicHash.

Member Function Documentation

[explicit] QMessageAuthenticationCode::QMessageAuthenticationCode(QCryptographicHash::Algorithm method, QByteArrayView key = {})

Constructs an object that computes HMACs with the algorithm method and the given key.

See also setKey().

QMessageAuthenticationCode::~QMessageAuthenticationCode()

Destroys the object.

void QMessageAuthenticationCode::addData(QByteArrayView data)

Adds data to the message.

See also result().

void QMessageAuthenticationCode::addData(const char *data, qsizetype length)

This is an overloaded function.

Adds the length bytes at data to the message.

bool QMessageAuthenticationCode::addData(QIODevice *device)

This is an overloaded function.

Reads from device until it is exhausted and adds the data. Returns true if all the data was read; otherwise returns false.

[static] QByteArray QMessageAuthenticationCode::hash(QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)

Returns the HMAC of message computed with the secret key and the algorithm method.

See also result().

[static] QByteArrayView QMessageAuthenticationCode::hashInto(QSpan<char> buffer, QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method)

Computes the HMAC of message with the secret key and the algorithm method, and writes it to buffer. Returns a view of the code inside buffer, or a null view if buffer is too small for it.

This function was introduced in 6.8.

See also hash() and QCryptographicHash::hashLength().

void QMessageAuthenticationCode::reset()

Resets the object, discarding all data added so far but keeping the key.

See also setKey().

QByteArray QMessageAuthenticationCode::result() const

Returns the HMAC of the data added so far. The object stays usable, and more data may be added afterwards.

See also resultView() and reset().

QByteArrayView QMessageAuthenticationCode::resultView() const

Returns the HMAC of the data added so far as a view. The view is valid until the next call to resultView() or until the object is modified or destroyed.

See also result().

void QMessageAuthenticationCode::setKey(QByteArrayView key)

Sets the secret to key and resets the object, discarding all data added so far.

See also reset().