Qt中包含了大部分常用的功能,比如json、数据库、网络通信、串口通信以及今天说的这个MD5加密;

Qt中将字符串进行MD5加密其实比较简单,代码如下:

#include <QCoreApplication>
#include <QCryptographicHash>
#include <QDebug>

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);


    QString str = "123456";
    QString md5Str = QCryptographicHash::hash(str.toLatin1(),QCryptographicHash::Md5).toHex();

    qDebug()<<"md5: "<<md5Str;

    return a.exec();
}

执行结果:

md5:  "e10adc3949ba59abbe56e057f20f883e"

MD5加密是不可逆的(不过现在据说有破解的),我们在程序中如果是使用MD5加密去保存密码的话,那么对比密码时,需要转换为MD5字符串后进行对比。

在网站https://www.sojson.com/encrypt_md5.html上可以在线计算MD5的加密值,与qt计算的值一致:

Qt使用MD5加密

微信公众号:

Qt使用MD5加密

 

相关文章:

  • 2022-12-23
  • 2021-11-19
  • 2021-10-25
  • 2021-10-05
  • 2022-01-14
  • 2022-01-14
  • 2022-01-26
  • 2022-01-15
猜你喜欢
  • 2021-12-31
  • 2022-01-31
  • 2022-02-18
  • 2022-02-12
  • 2022-02-24
  • 2021-08-21
  • 2022-12-23
相关资源
相似解决方案