Qt MD5算法加密

来源:互联网 发布:pdf在线阅读js 编辑:程序博客网 时间:2024/05/16 22:02

下面演示,将username 和 password加密的过程

#include <QGui>

   QString username = "admin";QString password = "admin123";   QString fileName="./pwd.txt";        QFile file(fileName);        if(!file.open(QIODevice::ReadWrite | QIODevice::Text))        {           QMessageBox::warning(this,"warning","文件操作错误",QMessageBox::Yes);        }        QTextStream in(&file);/**********加密开始***********/        QString usernamemd5;        QString pwdmd5;       QByteArray bb;        bb = QCryptographicHash::hash ( password.toAscii(), QCryptographicHash::Md5 );        pwdmd5.append(bb.toHex());        bb = QCryptographicHash::hash(username.toAscii(),QCryptographicHash::Md5);        usernamemd5.append(bb.toHex());/***********加密结束****************/        //QMessageBox::warning(this,"warning",usernamemd5,QMessageBox::Yes);        in<<usernamemd5+"\n";        in<<pwdmd5+"\n";        file.close();//到文件里看结果吧~当然用上面的消息框也可以哦