QCryptographicHash

QCryptographicHash 

Header: #include <QCryptographicHash>
qmake: QT += core
Since: Qt 4.3

 

注意:在5.9之前的Qt版本中,当被要求生成SHA3时,qcryptographicshash实际上计算了Keccak。如果您需要与Qt版本生成的SHA-3哈希兼容,请使用Keccak_u枚举器。或者,如果需要源兼容性,则定义宏QT_uSha3\u KECCAK_uUcompat。

 

ConstantValueDescription
QCryptographicHash::Md4 0 Generate an MD4 hash sum
QCryptographicHash::Md5 1 Generate an MD5 hash sum
QCryptographicHash::Sha1 2 Generate an SHA-1 hash sum
QCryptographicHash::Sha224 3 Generate an SHA-224 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha256 4 Generate an SHA-256 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha384 5 Generate an SHA-384 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha512 6 Generate an SHA-512 hash sum (SHA-2). Introduced in Qt 5.0
QCryptographicHash::Sha3_224 RealSha3_224 Generate an SHA3-224 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_256 RealSha3_256 Generate an SHA3-256 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_384 RealSha3_384 Generate an SHA3-384 hash sum. Introduced in Qt 5.1
QCryptographicHash::Sha3_512 RealSha3_512 Generate an SHA3-512 hash sum. Introduced in Qt 5.1
QCryptographicHash::Keccak_224 7 Generate a Keccak-224 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_256 8 Generate a Keccak-256 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_384 9 Generate a Keccak-384 hash sum. Introduced in Qt 5.9.2
QCryptographicHash::Keccak_512 10 Generate a Keccak-512 hash sum. Introduced in Qt 5.9.2

 

 

 

void MainWindow::getMd5(QString pwdStr)
{
    QString md5Str;
    QByteArray byteArray1, byteArray2;
    QCryptographicHash md(QCryptographicHash::Md5);
    byteArray1.append(pwdStr);
    md.addData(byteArray1);
    byteArray2 = md.result();
    md5Str.append(byteArray2.toHex());
    qDebug() << md5Str;

    return md5Str;    
}

 

 

Md5:
a94db642b34e5f34d75c14c5aeeda36f


Keccak_512:
a95c153b9bd4b32910b08c7d591866d949df2aa3e3fb62ed423ea5fd72c3e4ca05b2f1baa8a01fba9054a797589660f0988e22654ad3b0a77eee391b8bf5686b

 

 

################

posted @ 2021-06-24 10:22  西北逍遥  阅读(466)  评论(6编辑  收藏  举报