このページでは

QCryptographicHash Class

QCryptographicHash クラスは、暗号ハッシュを生成する手段を提供します。詳細...

ヘッダー: #include <QCryptographicHash>
CMake: find_package(Qt6 REQUIRED COMPONENTS Core)
target_link_libraries(mytarget PRIVATE Qt6::Core)
qmake: QT += core

注:このクラスのすべての関数は再入可能である。

パブリック型

enum Algorithm { Md4, Md5, Sha1, Sha224, Sha256, …, Blake2s_256 }

パブリック関数

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)

静的パブリックメンバー

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)

詳細な説明

QCryptographicHash を使用すると、バイナリデータやテキストデータの暗号ハッシュを生成できます。

サポートされているアルゴリズムの一覧については、QCryptographicHash::Algorithm 列挙型のドキュメントを参照してください。

メンバ型のドキュメント

enum QCryptographicHash::Algorithm

注: Qt 5.9 以前のバージョンでは 、SHA3 ハッシュ値の生成が要求された場合、QCryptographicHash は実際には Keccak を計算していました。これらのバージョンの Qt で生成された SHA-3 ハッシュとの互換性が必要な場合は、Keccak_ 列挙子を使用してください。あるいは、ソースコードの互換性が必要な場合は、マクロQT_SHA3_KECCAK_COMPAT を定義してください。

定数値説明
QCryptographicHash::Md40MD4ハッシュ値を生成する
QCryptographicHash::Md51MD5 ハッシュ値を生成
QCryptographicHash::Sha12SHA-1ハッシュ値を生成する
QCryptographicHash::Sha2243SHA-224 ハッシュ値(SHA-2)を生成します。Qt 5.0 で導入されました
QCryptographicHash::Sha2564SHA-256 ハッシュ値 (SHA-2) を生成します。Qt 5.0 で導入されました
QCryptographicHash::Sha3845SHA-384 ハッシュ値 (SHA-2) を生成します。Qt 5.0 で導入されました
QCryptographicHash::Sha5126SHA-512 ハッシュ値 (SHA-2) を生成します。Qt 5.0 で導入されました
QCryptographicHash::Sha3_224RealSha3_224SHA3-224 ハッシュ値を生成します。Qt 5.1 で導入されました
QCryptographicHash::Sha3_256RealSha3_256SHA3-256ハッシュ値を生成します。Qt 5.1で導入されました
QCryptographicHash::Sha3_384RealSha3_384SHA3-384 ハッシュ値を生成します。Qt 5.1 で導入されました
QCryptographicHash::Sha3_512RealSha3_512SHA3-512 ハッシュ値を生成します。Qt 5.1 で導入されました
QCryptographicHash::Keccak_2247Keccak-224 ハッシュ値を生成します。Qt 5.9.2 で導入されました
QCryptographicHash::Keccak_2568Keccak-256 ハッシュ値を生成します。Qt 5.9.2 で導入されました
QCryptographicHash::Keccak_3849Keccak-384 ハッシュ値を生成します。Qt 5.9.2 で導入されました
QCryptographicHash::Keccak_51210Keccak-512 ハッシュ値を生成します。Qt 5.9.2 で導入されました
QCryptographicHash::Blake2b_16015BLAKE2b-160 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2b_25616BLAKE2b-256 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2b_38417BLAKE2b-384 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2b_51218BLAKE2b-512 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2s_12819BLAKE2s-128 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2s_16020BLAKE2s-160 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2s_22421BLAKE2s-224 ハッシュ値を生成します。Qt 6.0 で導入されました
QCryptographicHash::Blake2s_25622BLAKE2s-256 ハッシュ値を生成します。Qt 6.0 で導入されました

メンバ関数のドキュメント

[explicit] QCryptographicHash::QCryptographicHash(QCryptographicHash::Algorithm method)

method を使用して、データから暗号ハッシュを生成するために使用できるオブジェクトを構築します。

[noexcept, since 6.5] QCryptographicHash::QCryptographicHash(QCryptographicHash &&other)

other から新しい QCryptographicHash を移動生成します。

注: 移動元のオブジェクト other は 、部分的に形成された状態となり、この状態では破棄と新しい値への代入のみが有効な操作となります。

この関数は Qt 6.5 で導入されました。

[noexcept] QCryptographicHash::~QCryptographicHash()

オブジェクトを破棄します。

[noexcept] void QCryptographicHash::addData(QByteArrayView bytes)

bytes に含まれる文字を暗号ハッシュに追加します。

注: Qt 6.3 以前のバージョンでは 、この関数は `QByteArrayView` ではなく `QByteArray` を引数としていました。

bool QCryptographicHash::addData(QIODevice *device)

開いているQIODevice device からデータが終了するまで読み込み、ハッシュ化します。読み込みが成功した場合は、true を返します。

[noexcept, since 6.5] QCryptographicHash::Algorithm QCryptographicHash::algorithm() const

暗号ハッシュの生成に使用されたアルゴリズムを返します。

この関数は Qt 6.5 で導入されました。

[static] QByteArray QCryptographicHash::hash(QByteArrayView data, QCryptographicHash::Algorithm method)

method を使用して、data のハッシュを返します。

注: Qt 6.3 以前のバージョンでは 、この関数は `QByteArrayView` ではなく `QByteArray` を受け取っていました。

関連項目: 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)

method を使用してdata のハッシュを返し、buffer を使用して結果を格納します。

data がスパンである場合、指定された順序ですべてのバイト配列ビューをハッシュに追加します。

戻り値はbuffer のサブスパンとなります。ただし、buffer のサイズが不十分な場合は、QByteArrayView が null として返されます。

これらの関数は Qt 6.8 で導入されました。

hash()も参照してください 。

[static] int QCryptographicHash::hashLength(QCryptographicHash::Algorithm method)

選択したハッシュmethod の出力サイズをバイト単位で返します。

[noexcept] void QCryptographicHash::reset()

オブジェクトをリセットします。

QByteArray QCryptographicHash::result() const

最終的なハッシュ値を返します。

resultView() およびQByteArray::toHex()も参照してください 。

[noexcept, since 6.3] QByteArrayView QCryptographicHash::resultView() const

最終的なハッシュ値を返します。

なお、返されたビューは、QCryptographicHash オブジェクトが他の手段によって変更されない限り、有効なままとなります。

この関数は Qt 6.3 で導入されました。

result()も参照してください 。

[static, since 6.5] bool QCryptographicHash::supportsAlgorithm(QCryptographicHash::Algorithm method)

選択されたアルゴリズムmethod がサポートされているかどうか、およびmethod が使用された際にresult()が値を返すかどうかを返します。

注:OpenSSLが プロバイダとして使用される場合、この情報の提供はOpenSSLが行います。それ以外の場合は、非OpenSSL実装には制限がないため、true が返されます。OpenSSLへの問い合わせに失敗した場合は、false を返します。

この関数は Qt 6.5 で導入されました。

[noexcept, since 6.5] void QCryptographicHash::swap(QCryptographicHash &other)

この暗号ハッシュをother と入れ替えます。この操作は非常に高速で、失敗することはありません。

この関数は Qt 6.5 で導入されました。

[noexcept, since 6.5] QCryptographicHash &QCryptographicHash::operator=(QCryptographicHash &&other)

other をこのQCryptographicHash インスタンスに代入します。

注: 移動元のオブジェクト other は 、部分的に形成された状態になります。この状態では、有効な操作は破棄と新しい値への代入のみです。

この関数は 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.