QMessageAuthenticationCodeclass provides a way to generate hash-based message authentication codes. 更多 …
QMessageAuthenticationCodesupports all cryptographic hashes which are supported byQCryptographicHash.To generate message authentication code, pass hash algorithm
Algorithmto constructor, then set key and message bysetKey()andaddData()functions. Result can be acquired byresult()函数。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();另请参阅
QMessageAuthenticationCode
(
方法
[
,
key=QByteArray()
]
)
¶
- param method
Algorithm- param key
Constructs an object that can be used to create a cryptographic hash from data using method
方法
and key
key
.
PySide2.QtCore.QMessageAuthenticationCode.
addData
(
device
)
¶
device
–
QIODevice
bool
读取数据,从打开
QIODevice
device
until it ends and adds it to message. Returns
true
若读取是成功的。
注意
device
must be already opened.
PySide2.QtCore.QMessageAuthenticationCode.
addData
(
data
)
¶
data
–
QByteArray
PySide2.QtCore.QMessageAuthenticationCode.
addData
(
data
,
length
)
¶
data – str
length
–
int
Adds the first
length
chars of
data
to the message.
PySide2.QtCore.QMessageAuthenticationCode.
hash
(
message
,
key
,
方法
)
¶
message
–
QByteArray
key
–
QByteArray
方法
–
Algorithm
Returns the authentication code for the message
message
using the key
key
and the method
方法
.
PySide2.QtCore.QMessageAuthenticationCode.
reset
(
)
¶
Resets message data. Calling this method doesn’t affect the key.
PySide2.QtCore.QMessageAuthenticationCode.
result
(
)
¶
Returns the final authentication code.
另请参阅
PySide2.QtCore.QMessageAuthenticationCode.
setKey
(
key
)
¶
key
–
QByteArray
Sets secret
key
. Calling this method automatically resets the object state.