![]() |
Qt 6.x
The Qt SDK
|
\inmodule QtNetwork More...
Functions | |
Q_NETWORK_EXPORT QByteArray | deriveKeyPbkdf1 (QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen) |
Q_NETWORK_EXPORT QByteArray | deriveKeyPbkdf2 (QCryptographicHash::Algorithm algorithm, const QByteArray &data, const QByteArray &salt, int iterations, quint64 dkLen) |
\inmodule QtNetwork
The QPasswordDigestor namespace contains functions which you can use to generate hashes or keys.
Q_NETWORK_EXPORT QByteArray QPasswordDigestor::deriveKeyPbkdf1 | ( | QCryptographicHash::Algorithm | algorithm, |
const QByteArray & | data, | ||
const QByteArray & | salt, | ||
int | iterations, | ||
quint64 | dkLen | ||
) |
Returns a hash computed using the PBKDF1-algorithm as defined in \l {RFC 8018, section 5.1}.
The function takes the data and salt, and then hashes it repeatedly for iterations iterations using the specified hash algorithm. If the resulting hash is longer than dkLen then it is truncated before it is returned.
This function only supports SHA-1 and MD5! The max output size is 160 bits (20 bytes) when using SHA-1, or 128 bits (16 bytes) when using MD5. Specifying a value for dkLen which is greater than this results in a warning and an empty QByteArray is returned. To programmatically check this limit you can use \l {QCryptographicHash::hashLength}. Furthermore: the salt must always be 8 bytes long!
Definition at line 57 of file qpassworddigestor.cpp.
References hash, QCryptographicHash::hashLength(), i, QCryptographicHash::Md5, qWarning, QCryptographicHash::Sha1, and QByteArray::size().
Referenced by QTlsPrivate::Q_GLOBAL_STATIC_WITH_ARGS().
Q_NETWORK_EXPORT QByteArray QPasswordDigestor::deriveKeyPbkdf2 | ( | QCryptographicHash::Algorithm | algorithm, |
const QByteArray & | data, | ||
const QByteArray & | salt, | ||
int | iterations, | ||
quint64 | dkLen | ||
) |
Derive a key using the PBKDF2-algorithm as defined in \l {RFC 8018, section 5.2}.
This function takes the data and salt, and then applies HMAC-X, where the X is algorithm, repeatedly. It internally concatenates intermediate results to the final output until at least dkLen amount of bytes have been computed and it will execute HMAC-X iterations times each time a concatenation is required. The total number of times it will execute HMAC-X depends on iterations, dkLen and algorithm and can be calculated as {iterations * ceil(dkLen / QCryptographicHash::hashLength(algorithm))}.
Definition at line 196 of file qpassworddigestor.cpp.
References QMessageAuthenticationCode::addData(), QByteArray::begin(), QByteArray::cbegin(), QByteArray::cend(), QCryptographicHash::hashLength(), iter, QByteArray::left(), qToBigEndian(), qWarning, QMessageAuthenticationCode::reset(), QMessageAuthenticationCode::result(), and Qt::Uninitialized.
Referenced by QTlsPrivate::Q_GLOBAL_STATIC_WITH_ARGS().