PySide6.QtCore.QCryptographicHash

class QCryptographicHash

QCryptographicHash 类提供了一种生成加密哈希的方法。更多

概要

方法

静态函数

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

QCryptographicHash 可用于生成二进制或文本数据的加密哈希值。

请参考Algorithm枚举的文档以获取支持的算法列表。

class Algorithm

注意

在5.9之前的Qt版本中,当要求生成SHA3哈希值时,QCryptographicHash实际上计算的是Keccak。如果您需要与这些Qt版本生成的SHA-3哈希值兼容,请使用Keccak_枚举器。或者,如果需要源代码兼容性,请定义宏QT_SHA3_KECCAK_COMPAT

常量

描述

QCryptographicHash.Md4

生成一个MD4哈希值

QCryptographicHash.Md5

生成一个MD5哈希值

QCryptographicHash.Sha1

生成一个SHA-1哈希值

QCryptographicHash.Sha224

生成一个SHA-224哈希值(SHA-2)。在Qt 5.0中引入

QCryptographicHash.Sha256

生成一个SHA-256哈希值(SHA-2)。在Qt 5.0中引入

QCryptographicHash.Sha384

生成一个SHA-384哈希值(SHA-2)。在Qt 5.0中引入

QCryptographicHash.Sha512

生成一个SHA-512哈希值(SHA-2)。在Qt 5.0中引入

QCryptographicHash.Sha3_224

生成一个SHA3-224哈希值。在Qt 5.1中引入

QCryptographicHash.Sha3_256

生成一个SHA3-256哈希值。在Qt 5.1中引入

QCryptographicHash.Sha3_384

生成一个SHA3-384哈希值。在Qt 5.1中引入

QCryptographicHash.Sha3_512

生成一个SHA3-512哈希值。在Qt 5.1中引入

QCryptographicHash.Keccak_224

生成一个Keccak-224哈希值。在Qt 5.9.2中引入

QCryptographicHash.Keccak_256

生成一个Keccak-256哈希值。在Qt 5.9.2中引入

QCryptographicHash.Keccak_384

生成一个Keccak-384哈希值。在Qt 5.9.2中引入

QCryptographicHash.Keccak_512

生成一个Keccak-512哈希值。在Qt 5.9.2中引入

QCryptographicHash.Blake2b_160

生成一个BLAKE2b-160哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2b_256

生成一个BLAKE2b-256哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2b_384

生成一个BLAKE2b-384哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2b_512

生成一个BLAKE2b-512哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2s_128

生成一个BLAKE2s-128哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2s_160

生成一个BLAKE2s-160哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2s_224

生成一个BLAKE2s-224哈希值。在Qt 6.0中引入

QCryptographicHash.Blake2s_256

生成一个BLAKE2s-256哈希值。在Qt 6.0中引入

__init__(method)
Parameters:

方法算法

构造一个对象,该对象可用于使用method从数据创建加密哈希。

addData(data)
Parameters:

数据QByteArrayView

bytes中的字符添加到加密哈希中。

注意

在Qt 6.3之前的版本中,此函数接受的是QByteArray,而不是QByteArrayView

addData(device)
Parameters:

设备QIODevice

Return type:

布尔

从打开的QIODevice device中读取数据直到结束并对其进行哈希处理。如果读取成功,则返回true

addData(data)
Parameters:

data – 字符串

注意

此函数已弃用。

data的前length个字符添加到加密哈希中。

请改用QByteArrayView的重载。

algorithm()
Return type:

算法

返回用于生成加密哈希的算法。

static hash(data, method)
Parameters:
  • dataQByteArrayView

  • method算法

Return type:

QByteArray

返回使用methoddata的哈希值。

注意

在Qt 6.3之前的版本中,此函数接受的是QByteArray,而不是QByteArrayView

另请参阅

hashInto()

static hashLength(method)
Parameters:

方法算法

Return type:

整数

返回所选哈希method输出的大小(以字节为单位)。

reset()

重置对象。

result()
Return type:

QByteArray

返回最终的哈希值。

另请参阅

resultView() toHex()

resultView()
Return type:

QByteArrayView

返回最终的哈希值。

请注意,返回的视图仅在QCryptographicHash对象未被其他方式修改时保持有效。

另请参阅

result()

static supportsAlgorithm(method)
Parameters:

方法算法

Return type:

布尔

返回所选算法method是否受支持,以及当使用methodresult()是否会返回值。

注意

当使用OpenSSL作为提供者时,OpenSSL将负责提供此信息,否则将返回true,因为非OpenSSL实现没有任何限制。如果我们无法查询OpenSSL,则返回false

swap(other)
Parameters:

其他QCryptographicHash

将此加密哈希与other加密哈希交换。此操作非常快速且永远不会失败。