QPasswordDigestor Namespace
QPasswordDigestor 命名空间包含可用于生成哈希值或密钥的函数。更多
头文件: | #include <QPasswordDigestor> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Network) target_link_libraries(mytarget PRIVATE Qt6::Network) |
qmake: | QT += network |
功能
QByteArray | deriveKeyPbkdf1(QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen) |
QByteArray | deriveKeyPbkdf2(QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen) |
函数文档
QByteArray QPasswordDigestor::deriveKeyPbkdf1(QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen)
返回使用RFC 8018 第 5.1 节定义的 PBKDF1 算法计算的散列值。
该函数获取data 和salt ,然后使用指定的哈希值algorithm 对其进行iterations 反复迭代哈希。如果散列结果长于dkLen ,则在返回前将其截断。
该函数仅支持 SHA-1 和 MD5!使用 SHA-1 时,最大输出大小为 160 位(20 字节);使用 MD5 时,最大输出大小为 128 位(16 字节)。如果为dkLen 指定的值大于此值,则会发出警告,并返回一个空的QByteArray 。要以编程方式检查这一限制,可以使用QCryptographicHash::hashLength 。此外:salt 的长度必须始终为 8 字节!
注意: 该函数是为传统应用程序提供的,建议所有新应用程序使用PBKDF2 。
另请参阅 deriveKeyPbkdf2,QCryptographicHash, 和QCryptographicHash::hashLength 。
QByteArray QPasswordDigestor::deriveKeyPbkdf2(QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen)
使用RFC 8018 第 5.2 节定义的 PBKDF2- 算法生成密钥。
该函数接收data 和salt ,然后重复应用 HMAC-X(其中 X 为algorithm )。它在内部将中间结果连接到最终输出,直到至少计算出dkLen 个字节,每次需要连接时,它都会执行 HMAC-Xiterations 次。执行 HMAC-X 的总次数取决于iterations,dkLen 和algorithm ,可按iterations * ceil(dkLen / QCryptographicHash::hashLength(algorithm))
计算。
另请参见 deriveKeyPbkdf1,QMessageAuthenticationCode, 和QCryptographicHash 。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.