QT中生成字符串md5的方法

QT中,提供了QCryptographicHash类,很方便的实现的字符串到md5/md4/sha1的转换,可以通过两种方法实现:

QString pwd="123456";
QString md5;
QByteArray ba,bb;
QCryptographicHash md(QCryptographicHash::Md5);
ba.append(pwd);
md.addData(ba);
bb = md.result();
md5.append(bb.toHex()); 

第二种方法比较直接:

QString md5;
QString pwd="123456";
QByteArray bb;
bb = QCryptographicHash::hash ( pwd.toAscii(), QCryptographicHash::Md5 );
md5.append(bb.toHex());


你可能感兴趣的:(MD5,hash,qt)