QMessageAuthenticationCode 类

QMessageAuthenticationCode class provides a way to generate hash-based message authentication codes. 更多...

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

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

公共函数

QMessageAuthenticationCode (QCryptographicHash::Algorithm method , const QByteArray & key = QByteArray())
~QMessageAuthenticationCode ()
void addData (const char * data , int length )
void addData (const QByteArray & data )
bool addData (QIODevice * device )
void reset ()
QByteArray result () const
void setKey (const QByteArray & key )

静态公共成员

QByteArray hash (const QByteArray & message , const QByteArray & key , QCryptographicHash::Algorithm method )

详细描述

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

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 () 和 addData () functions. Result can be acquired by result () 函数。

    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 () 方法。

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

另请参阅 QCryptographicHash .

成员函数文档编制

QMessageAuthenticationCode:: QMessageAuthenticationCode ( QCryptographicHash::Algorithm method , const QByteArray & key = QByteArray())

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

QMessageAuthenticationCode:: ~QMessageAuthenticationCode ()

销毁对象。

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

Adds the first length chars of data to the message.

void QMessageAuthenticationCode:: addData (const QByteArray & data )

此函数重载 addData ().

bool QMessageAuthenticationCode:: addData ( QIODevice * device )

读取数据,从打开 QIODevice device until it ends and adds it to message. Returns true 若读取是成功的。

注意: device must be already opened.

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

Returns the authentication code for the message message using the key key and the method method .

void QMessageAuthenticationCode:: reset ()

Resets message data. Calling this method doesn't affect the key.

QByteArray QMessageAuthenticationCode:: result () const

Returns the final authentication code.

另请参阅 QByteArray::toHex ().

void QMessageAuthenticationCode:: setKey (const QByteArray & key )

Sets secret key . Calling this method automatically resets the object state.