QMessageAuthenticationCode Class

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

Header: #include <QMessageAuthenticationCode>
qmake: QT += core
Since: Qt 5.1

This class was introduced in Qt 5.1.

Note: All functions in this class are reentrant.

Detailed Description

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.

     QByteArray key = "key";
     QByteArray message = "The quick brown fox jumps over the lazy dog";
     ...
     QMessageAuthenticationCode code(QCryptographicHash::Sha1);
     code.setKey(key);
     code.addData(message);
     code.result().toHex();      // returns "de7c9b85b8b78aa6bc8a7a36f70a90701c9db4d9"

Alternatively, this effect can be achieved by providing message, key and method to hash() method.

     QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha1).toHex();

See also QCryptographicHash.