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

 

版权声明
文章标题:QCryptographicHash类使用
文章链接:https://blog.chiyuba.com/houduanjishu/qt/123.html
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布,转载或引用请注明出处。
温馨提示:本文最后更新于 2021年6月16日,部分内容可能存在时效性,请注意甄别。

相关推荐

更多教程
QLabel启用复制功能 Qt QLabel启用复制功能

实现方式 ui->label_sh...

35 浏览
QML应⽤动画(Applying Animations)分类 Qt QML应⽤动画(Applying Animations)分类

QML动画应用分类 属性动画 - 在元素...

20 浏览
QtCreater Release下调试方法 Qt QtCreater Release下调试方法

前言 最近项目中,使用的库是releas...

19 浏览

评论