QMessageAuthenticationCode#
The QMessageAuthenticationCode
class provides a way to generate hash-based message authentication codes. More…
Synopsis#
Functions#
Static functions#
def
hash
(message, key, method)
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
QMessageAuthenticationCode
supports all cryptographic hashes which are supported by QCryptographicHash
.
To generate message authentication code, pass hash algorithm Algorithm
to constructor, then set key and message by setKey()
and addData()
functions. Result can be acquired by result()
function.
key = "key" message = "The quick brown fox jumps over the lazy dog" ... code = QMessageAuthenticationCode(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
- class PySide6.QtCore.QMessageAuthenticationCode(method[, key=QByteArray()])#
- Parameters:
method –
Algorithm
Constructs an object that can be used to create a cryptographic hash from data using method method
and key key
.
- PySide6.QtCore.QMessageAuthenticationCode.addData(device)#
- Parameters:
device –
PySide6.QtCore.QIODevice
- Return type:
bool
Reads the data from the open QIODevice
device
until it ends and adds it to message. Returns true
if reading was successful.
Note
device
must be already opened.
- PySide6.QtCore.QMessageAuthenticationCode.addData(data)
- Parameters:
data –
PySide6.QtCore.QByteArray
This function overloads addData()
.
- PySide6.QtCore.QMessageAuthenticationCode.addData(data, length)
- Parameters:
data – str
length –
qsizetype
Adds the first length
chars of data
to the message.
- static PySide6.QtCore.QMessageAuthenticationCode.hash(message, key, method)#
- Parameters:
message –
PySide6.QtCore.QByteArray
method –
Algorithm
- Return type:
Returns the authentication code for the message message
using the key key
and the method method
.
- PySide6.QtCore.QMessageAuthenticationCode.reset()#
Resets message data. Calling this method doesn’t affect the key.
- PySide6.QtCore.QMessageAuthenticationCode.result()#
- Return type:
Returns the final authentication code.
See also
- PySide6.QtCore.QMessageAuthenticationCode.setKey(key)#
- Parameters:
Sets secret key
. Calling this method automatically resets the object state.