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 ,并且每次需要进行拼接时,都会执行iterations 次HMAC-X。 HMAC-X 的总执行次数取决于iterations 、dkLen 和algorithm ,可通过公式iterations * ceil(dkLen / QCryptographicHash::hashLength(algorithm)) 计算得出。
另请参阅 deriveKeyPbkdf1 、QMessageAuthenticationCode 以及QCryptographicHash 。
© 2026 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.