QCryptographicHash类使用
前言
最近项目中有个需求:判断一个编辑界面的数据是否被编辑过。可能大家一般想的都是直接等(如果数据量大了效率会降低)就是了或者设置标志位,但是今天学到一种新思路采用md5加密的方式。其实我印象中md5有两个作用,一般是密码用到md5加密,过了就是文件校验用md5。
正文如下
QString pwd = QStringLiteral("此处省略一万字...");
QString md5Value;
QByteArray md5Byte = QCryptographicHash::hash(pwd.toUtf8(), QCryptographicHash::Md5);
md5Value.append(md5Byte.toHex());
qDebug() << __FUNCTION__ << __LINE__ << " : " << md5Value;
可选参数
枚举 | 枚举值 | 描述 |
---|---|---|
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 |
版权声明:
作者:小何
链接:https://ligo100.cn/houduanjishu/qt/123.html
来源:小何博客
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
打赏
文章目录
关闭
共有 0 条评论