MochiuWiki : SUSE, EC, PCB
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
検索
個人用ツール
ログイン
Toggle dark mode
名前空間
ページ
議論
表示
閲覧
ソースを閲覧
履歴を表示
Qtの基礎 - ハッシュ値のソースを表示
提供: MochiuWiki : SUSE, EC, PCB
←
Qtの基礎 - ハッシュ値
あなたには「このページの編集」を行う権限がありません。理由は以下の通りです:
この操作は、次のグループのいずれかに属する利用者のみが実行できます:
管理者
、new-group。
このページのソースの閲覧やコピーができます。
== 概要 == Qtにおいて、ハッシュ値を求める手順を記載する。<br> <br><br> == ハッシュ化 == MD5、SHA-2、SHA-3等のハッシュを求める場合、<code>QCryptographicHash</code>クラスの<code>hash</code>メソッドを使用する。<br> <br> 以下の例では、任意の文字列から、MD4、MD5、SHA-2、SHA-3のハッシュを計算している。<br> <br> サポートされているハッシュの詳細については、[http://doc.qt.io/qt-5/qcryptographichash.html#Algorithm-enum Qtの公式ドキュメント]を参照すること。<br> <syntaxhighlight lang="c++"> #include <QCoreApplication> #include <QCryptographicHash> #include <QDebug> int main(int argc, char *argv[]) { QCoreApplication a(argc, argv); // ハッシュ化する文字列 QString input = "Hello, world!"; // MD4 QByteArray md4Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Md4); QString md4HexHash = md4Hash.toHex(); qDebug() << "MD4 Hash:" << md4HexHash; // MD5 QByteArray md5Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Md5); QString md5HexHash = md5Hash.toHex(); qDebug() << "MD5 Hash:" << md5HexHash; // SHA-2 (SHA-224) QByteArray sha224Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha224); QString sha224HexHash = sha224Hash.toHex(); qDebug() << "SHA-2 (SHA-224) Hash:" << sha224HexHash; // SHA-2 (SHA-256) QByteArray sha256Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha256); QString sha256HexHash = sha256Hash.toHex(); qDebug() << "SHA-2 (SHA-256) Hash:" << sha256HexHash; // SHA-2 (SHA-384) QByteArray sha384Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha384); QString sha384HexHash = sha384Hash.toHex(); qDebug() << "SHA-2 (SHA-384) Hash:" << sha384HexHash; // SHA-2 (SHA-512) QByteArray sha512Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha512); QString sha512HexHash = sha512Hash.toHex(); qDebug() << "SHA-2 (SHA-512) Hash:" << sha512HexHash; // SHA-3 (SHA3-224) QByteArray sha3_224Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha3_224); QString sha3_224HexHash = sha3_224Hash.toHex(); qDebug() << "SHA-3 (SHA3-224) Hash:" << sha3_224HexHash; // SHA-3 (SHA3-256) QByteArray sha3_256Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha3_256); QString sha3_256HexHash = sha3_256Hash.toHex(); qDebug() << "SHA-3 (SHA3-256) Hash:" << sha3_256HexHash; // SHA-3 (SHA3-384) QByteArray sha3_384Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha3_384); QString sha3_384HexHash = sha3_384Hash.toHex(); qDebug() << "SHA-3 (SHA3-384) Hash:" << sha3_384HexHash; // SHA-3 (SHA3-512) QByteArray sha3_512Hash = QCryptographicHash::hash(input.toUtf8(), QCryptographicHash::Sha3_512); QString sha3_512HexHash = sha3_512Hash.toHex(); qDebug() << "SHA-3 (SHA3-512) Hash:" << sha3_512HexHash; return a.exec(); } </syntaxhighlight> <br><br> __FORCETOC__ [[カテゴリ:Qt]]
Qtの基礎 - ハッシュ値
に戻る。
案内
メインページ
最近の更新
おまかせ表示
MediaWiki についてのヘルプ
ツール
リンク元
関連ページの更新状況
特別ページ
ページ情報
We ask for
Donations
Collapse