QCryptographicHash Class
La classe QCryptographicHash consente di generare hash crittografici. Per saperne di più...
| Intestazione: | #include <QCryptographicHash> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Core) target_link_libraries(mytarget PRIVATE Qt6::Core) |
| qmake: | QT += core |
Nota: Tutte le funzioni di questa classe sono rientranti.
Tipi pubblici
| enum | Algorithm { Md4, Md5, Sha1, Sha224, Sha256, …, Blake2s_256 } |
Funzioni pubbliche
| QCryptographicHash(QCryptographicHash::Algorithm method) | |
(since 6.5) | QCryptographicHash(QCryptographicHash &&other) |
| ~QCryptographicHash() | |
| void | addData(QByteArrayView bytes) |
| bool | addData(QIODevice *device) |
(since 6.5) QCryptographicHash::Algorithm | algorithm() const |
| void | reset() |
| QByteArray | result() const |
(since 6.3) QByteArrayView | resultView() const |
(since 6.5) void | swap(QCryptographicHash &other) |
(since 6.5) QCryptographicHash & | operator=(QCryptographicHash &&other) |
Membri pubblici statici
| QByteArray | hash(QByteArrayView data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<char> buffer, QByteArrayView data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<std::byte> buffer, QByteArrayView data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<uchar> buffer, QByteArrayView data, QCryptographicHash::Algorithm method) |
(since 6.8) QByteArrayView | hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method) |
| int | hashLength(QCryptographicHash::Algorithm method) |
(since 6.5) bool | supportsAlgorithm(QCryptographicHash::Algorithm method) |
Descrizione dettagliata
QCryptographicHash può essere utilizzata per generare hash crittografici di dati binari o di testo.
Per un elenco degli algoritmi supportati, consultare la documentazione relativa all'enumerazione QCryptographicHash::Algorithm.
Documentazione sui tipi dei membri
enum QCryptographicHash::Algorithm
Nota: nelle versioni di Qt precedenti alla 5.9, quando veniva richiesta la generazione di una somma di controllo SHA-3, ` QCryptographicHash ` calcolava in realtà Keccak. Se è necessaria la compatibilità con le somme di controllo SHA-3 prodotte da tali versioni di Qt, utilizzare gli enumeratori ` Keccak_ `. In alternativa, se è richiesta la compatibilità a livello di codice sorgente, definire la macro ` QT_SHA3_KECCAK_COMPAT`.
| Costante | Valore | Descrizione |
|---|---|---|
QCryptographicHash::Md4 | 0 | Genera una somma di controllo MD4 |
QCryptographicHash::Md5 | 1 | Genera una somma di controllo MD5 |
QCryptographicHash::Sha1 | 2 | Genera una somma di controllo SHA-1 |
QCryptographicHash::Sha224 | 3 | Genera una somma di controllo SHA-224 (SHA-2). Introdotta in Qt 5.0 |
QCryptographicHash::Sha256 | 4 | Genera una somma di controllo SHA-256 (SHA-2). Introdotto in Qt 5.0 |
QCryptographicHash::Sha384 | 5 | Genera una somma di controllo SHA-384 (SHA-2). Introdotta in Qt 5.0 |
QCryptographicHash::Sha512 | 6 | Genera un valore di hash SHA-512 (SHA-2). Introdotto in Qt 5.0 |
QCryptographicHash::Sha3_224 | RealSha3_224 | Genera una somma di controllo SHA3-224. Introdotta in Qt 5.1 |
QCryptographicHash::Sha3_256 | RealSha3_256 | Genera una somma di controllo SHA3-256. Introdotta in Qt 5.1 |
QCryptographicHash::Sha3_384 | RealSha3_384 | Genera una somma di controllo SHA3-384. Introdotta in Qt 5.1 |
QCryptographicHash::Sha3_512 | RealSha3_512 | Genera una somma di controllo SHA3-512. Introdotto in Qt 5.1 |
QCryptographicHash::Keccak_224 | 7 | Genera una somma di controllo Keccak-224. Introdotta in Qt 5.9.2 |
QCryptographicHash::Keccak_256 | 8 | Genera una somma di hash Keccak-256. Introdotta in Qt 5.9.2 |
QCryptographicHash::Keccak_384 | 9 | Genera una somma di hash Keccak-384. Introdotto in Qt 5.9.2 |
QCryptographicHash::Keccak_512 | 10 | Genera una somma di hash Keccak-512. Introdotto in Qt 5.9.2 |
QCryptographicHash::Blake2b_160 | 15 | Genera una somma di hash BLAKE2b-160. Introdotta in Qt 6.0 |
QCryptographicHash::Blake2b_256 | 16 | Genera una somma di hash BLAKE2b-256. Introdotta in Qt 6.0 |
QCryptographicHash::Blake2b_384 | 17 | Genera una somma di controllo BLAKE2b-384. Introdotta in Qt 6.0 |
QCryptographicHash::Blake2b_512 | 18 | Genera una somma di hash BLAKE2b-512. Introdotta in Qt 6.0 |
QCryptographicHash::Blake2s_128 | 19 | Genera un hash BLAKE2s-128. Introdotto in Qt 6.0 |
QCryptographicHash::Blake2s_160 | 20 | Genera una somma di controllo BLAKE2s-160. Introdotto in Qt 6.0 |
QCryptographicHash::Blake2s_224 | 21 | Genera una somma di hash BLAKE2s-224. Introdotta in Qt 6.0 |
QCryptographicHash::Blake2s_256 | 22 | Genera una somma di controllo BLAKE2s-256. Introdotta in Qt 6.0 |
Documentazione delle funzioni membro
[explicit] QCryptographicHash::QCryptographicHash(QCryptographicHash::Algorithm method)
Crea un oggetto che può essere utilizzato per generare un hash crittografico dai dati utilizzando method.
[noexcept, since 6.5] QCryptographicHash::QCryptographicHash(QCryptographicHash &&other)
Crea un nuovo oggetto QCryptographicHash a partire da other.
Nota: l'oggetto da cui è stato effettuato lo spostamento, other, viene posto in uno stato parzialmente formato, in cui le uniche operazioni valide sono la distruzione e l'assegnazione di un nuovo valore.
Questa funzione è stata introdotta in Qt 6.5.
[noexcept] QCryptographicHash::~QCryptographicHash()
Elimina l'oggetto.
[noexcept] void QCryptographicHash::addData(QByteArrayView bytes)
Aggiunge i caratteri presenti in bytes all'hash crittografico.
Nota: nelle versioni di Qt precedenti alla 6.3, questa funzione accettava QByteArray, non QByteArrayView.
bool QCryptographicHash::addData(QIODevice *device)
Legge i dati dalla connessione aperta QIODevice device fino alla fine e ne calcola l'hash. Restituisce true se la lettura è andata a buon fine.
[noexcept, since 6.5] QCryptographicHash::Algorithm QCryptographicHash::algorithm() const
Restituisce l'algoritmo utilizzato per generare l'hash crittografico.
Questa funzione è stata introdotta in Qt 6.5.
[static] QByteArray QCryptographicHash::hash(QByteArrayView data, QCryptographicHash::Algorithm method)
Restituisce l'hash di data utilizzando method.
Nota: nelle versioni di Qt precedenti alla 6.3, questa funzione accettava QByteArray e non QByteArrayView.
Vedi anche hashInto().
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<char> buffer, QByteArrayView data, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<char> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<std::byte> buffer, QByteArrayView data, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<std::byte> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<uchar> buffer, QByteArrayView data, QCryptographicHash::Algorithm method)
[static noexcept, since 6.8] QByteArrayView QCryptographicHash::hashInto(QSpan<uchar> buffer, QSpan<const QByteArrayView> data, QCryptographicHash::Algorithm method)
Restituisce l'hash di data utilizzando method, utilizzando buffer per memorizzare il risultato.
Se data è uno span, aggiunge tutte le viste dell'array di byte all'hash, nell'ordine specificato.
Il valore restituito sarà uno span secondario di buffer, a meno che buffer non abbia dimensioni insufficienti; in tal caso, viene restituito un QByteArrayView nullo.
Queste funzioni sono state introdotte in Qt 6.8.
Vedi anche ` hash()`.
[static] int QCryptographicHash::hashLength(QCryptographicHash::Algorithm method)
Restituisce la dimensione in byte dell'output dell'method e hash selezionato.
[noexcept] void QCryptographicHash::reset()
Reimposta l'oggetto.
QByteArray QCryptographicHash::result() const
Restituisce il valore hash finale.
Vedi anche resultView() e QByteArray::toHex().
[noexcept, since 6.3] QByteArrayView QCryptographicHash::resultView() const
Restituisce il valore hash finale.
Si noti che la vista restituita rimane valida solo finché l'oggetto ` QCryptographicHash ` non viene modificato in altro modo.
Questa funzione è stata introdotta in Qt 6.3.
Vedi anche result().
[static, since 6.5] bool QCryptographicHash::supportsAlgorithm(QCryptographicHash::Algorithm method)
Restituisce se l'algoritmo selezionato method è supportato e se result() restituirà un valore quando viene utilizzato method.
Nota: OpenSSL sarà responsabile di fornire queste informazioni quando viene utilizzato come provider; in caso contrario, verrà restituito true poiché l’implementazione non OpenSSL non presenta alcuna restrizione. Restituiamo false se non riusciamo a interrogare OpenSSL.
Questa funzione è stata introdotta in Qt 6.5.
[noexcept, since 6.5] void QCryptographicHash::swap(QCryptographicHash &other)
Sostituisce questo hash crittografico con other. Questa operazione è molto veloce e non fallisce mai.
Questa funzione è stata introdotta in Qt 6.5.
[noexcept, since 6.5] QCryptographicHash &QCryptographicHash::operator=(QCryptographicHash &&other)
L'operazione "move-assign" assegna other a questa istanza di QCryptographicHash.
Nota: l'oggetto da cui è stato effettuato lo spostamento, ` other `, viene posto in uno stato parzialmente formato, in cui le uniche operazioni valide sono la distruzione e l'assegnazione di un nuovo valore.
Questa funzione è stata introdotta in Qt 6.5.
© 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.