Getting Sha1 hash from QString

我是研究僧i 提交于 2020-01-25 06:24:10

问题


In my Qt5.6.1 program, I have to get a Sha-1 hash from QString, but I get incorrect result. I'm trying to use QCryptographicHash library.

QString str = "ABCDEFGH";    
QString hash = QString::fromStdString(QCryptographicHash::hash(str.toStdString().c_str(), QCryptographicHash::Sha1).toStdString());
// hash == "?^??[?\u0000??v??\u0015??.b??v"

What should I change in that case?


回答1:


I think this answer will be useful for you it is for md5 How to create MD5 hash in Qt?

instead of str.toStdString().c_str() try using str.toUtf8() like this form the previous answer

QString hash = QString("%1").arg(QString(QCryptographicHash::hash(str.toUtf8(),QCryptographicHash::Sha1).toHex()))


来源:https://stackoverflow.com/questions/37763396/getting-sha1-hash-from-qstring

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!