![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtCore More...
#include <qmessageauthenticationcode.h>
Public Member Functions | |
QMessageAuthenticationCode (QCryptographicHash::Algorithm method, QByteArrayView key={}) | |
QMessageAuthenticationCode (QMessageAuthenticationCode &&other) noexcept | |
Move-constructs a new QMessageAuthenticationCode from other. | |
~QMessageAuthenticationCode () | |
Destroys the object. | |
void | swap (QMessageAuthenticationCode &other) noexcept |
Swaps message authentication code other with this message authentication code. | |
void | reset () noexcept |
Resets message data. | |
void | setKey (QByteArrayView key) noexcept |
Sets secret key. | |
void | addData (const char *data, qsizetype length) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the first length chars of data to the message. | |
void | addData (QByteArrayView data) noexcept |
Adds data to the message. | |
bool | addData (QIODevice *device) |
Reads the data from the open QIODevice device until it ends and adds it to message. | |
QByteArrayView | resultView () const noexcept |
QByteArray | result () const |
Returns the final authentication code. | |
Static Public Member Functions | |
static QByteArray | hash (QByteArrayView message, QByteArrayView key, QCryptographicHash::Algorithm method) |
Returns the authentication code for the message message using the key key and the method method. | |
\inmodule QtCore
The QMessageAuthenticationCode class provides a way to generate hash-based message authentication codes.
\reentrant
QMessageAuthenticationCode supports all cryptographic hashes which are supported by QCryptographicHash.
To generate message authentication code, pass hash algorithm QCryptographicHash::Algorithm to constructor, then set key and message by setKey() and addData() functions. Result can be acquired by result() function.
\dots
Alternatively, this effect can be achieved by providing message, key and method to hash() method.
Definition at line 16 of file qmessageauthenticationcode.h.
|
explicit |
Constructs an object that can be used to create a cryptographic hash from data using method \a method and key \a key.
! [qba-to-qbav-6.6]
{QByteArray{~~~}} to make the cast explicit. This is backwards-compatible with old Qt versions. ! [qba-to-qbav-6.6] Definition at line 1414 of file qcryptographichash.cpp.
References QMessageAuthenticationCodePrivate::setKey().
|
inlinenoexcept |
Move-constructs a new QMessageAuthenticationCode from other.
Definition at line 26 of file qmessageauthenticationcode.h.
References other().
QMessageAuthenticationCode::~QMessageAuthenticationCode | ( | ) |
Destroys the object.
Definition at line 1424 of file qcryptographichash.cpp.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts. Adds the first length chars of data to the message.
Definition at line 1513 of file qcryptographichash.cpp.
References QCryptographicHashPrivate::addData(), and QMessageAuthenticationCodePrivate::messageHash.
Referenced by _q_PKCS12_mac(), QPasswordDigestor::deriveKeyPbkdf2(), and dtlscallbacks::q_generate_cookie_callback().
|
noexcept |
Adds data to the message.
{qba-to-qbav-6.6}
Definition at line 1525 of file qcryptographichash.cpp.
References d.
bool QMessageAuthenticationCode::addData | ( | QIODevice * | device | ) |
Reads the data from the open QIODevice device until it ends and adds it to message.
Returns true
if reading was successful.
Definition at line 1536 of file qcryptographichash.cpp.
References QCryptographicHashPrivate::addData(), device, and QMessageAuthenticationCodePrivate::messageHash.
|
static |
Returns the authentication code for the message message using the key key and the method method.
{qba-to-qbav-6.6}
Definition at line 1592 of file qcryptographichash.cpp.
References QCryptographicHashPrivate::addData(), QMessageAuthenticationCodePrivate::finalizeUnchecked(), QMessageAuthenticationCodePrivate::messageHash, method, QCryptographicHashPrivate::resultView(), QMessageAuthenticationCodePrivate::setKey(), and QByteArrayView::toByteArray().
Referenced by main().
|
noexcept |
Resets message data.
Calling this method doesn't affect the key.
Definition at line 1465 of file qcryptographichash.cpp.
References QMessageAuthenticationCodePrivate::initMessageHash(), QMessageAuthenticationCodePrivate::messageHash, and QCryptographicHashPrivate::reset().
Referenced by QPasswordDigestor::deriveKeyPbkdf2().
QByteArray QMessageAuthenticationCode::result | ( | ) | const |
Returns the final authentication code.
Definition at line 1562 of file qcryptographichash.cpp.
References resultView(), and QByteArrayView::toByteArray().
Referenced by _q_PKCS12_mac(), and QPasswordDigestor::deriveKeyPbkdf2().
|
noexcept |
Returns the final hash value.
Note that the returned view remains valid only as long as the QMessageAuthenticationCode object is not modified by other means.
Definition at line 1551 of file qcryptographichash.cpp.
References QMessageAuthenticationCodePrivate::finalize(), QMessageAuthenticationCodePrivate::messageHash, and QCryptographicHashPrivate::resultView().
Referenced by dtlscallbacks::q_generate_cookie_callback(), and result().
|
noexcept |
Sets secret key.
Calling this method automatically resets the object state.
For optimal performance, call this method only to change the active key, not to set an initial key, as in
Prefer to pass initial keys as the constructor argument:
You can use std::optional to delay construction of a QMessageAuthenticationCode until you know the key:
{qba-to-qbav-6.6}
Definition at line 1503 of file qcryptographichash.cpp.
References d.
|
inlinenoexcept |
Swaps message authentication code other with this message authentication code.
This operation is very fast and never fails.
Definition at line 31 of file qmessageauthenticationcode.h.
References d, other(), and qt_ptr_swap().