QMessageAuthenticationCode

Inheritance diagram of PySide2.QtCore.QMessageAuthenticationCode

Synopsis

Functions

Static functions

  • def hash (message, key, method)

Detailed Description

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

PySide2.QtCore.QMessageAuthenticationCode supports all cryptographic hashes which are supported by PySide2.QtCore.QCryptographicHash .

To generate message authentication code, pass hash algorithm QCryptographicHash.Algorithm to constructor, then set key and message by PySide2.QtCore.QMessageAuthenticationCode.setKey() and PySide2.QtCore.QMessageAuthenticationCode.addData() functions. Result can be acquired by PySide2.QtCore.QMessageAuthenticationCode.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 PySide2.QtCore.QMessageAuthenticationCode.hash() method.

QMessageAuthenticationCode::hash(message, key, QCryptographicHash::Sha1).toHex();
class PySide2.QtCore.QMessageAuthenticationCode(method[, key=QByteArray()])
Parameters:

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

PySide2.QtCore.QMessageAuthenticationCode.addData(data, length)
Parameters:
  • data – str
  • lengthPySide2.QtCore.int

Adds the first length chars of data to the message.

PySide2.QtCore.QMessageAuthenticationCode.addData(data)
Parameters:dataPySide2.QtCore.QByteArray

This function overloads PySide2.QtCore.QMessageAuthenticationCode.addData() .

PySide2.QtCore.QMessageAuthenticationCode.addData(device)
Parameters:devicePySide2.QtCore.QIODevice
Return type:PySide2.QtCore.bool

Reads the data from the open PySide2.QtCore.QIODevice device until it ends and adds it to message. Returns true if reading was successful.

Note

device must be already opened.

static PySide2.QtCore.QMessageAuthenticationCode.hash(message, key, method)
Parameters:
Return type:

PySide2.QtCore.QByteArray

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

PySide2.QtCore.QMessageAuthenticationCode.reset()

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

PySide2.QtCore.QMessageAuthenticationCode.result()
Return type:PySide2.QtCore.QByteArray

Returns the final authentication code.

PySide2.QtCore.QMessageAuthenticationCode.setKey(key)
Parameters:keyPySide2.QtCore.QByteArray

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