在我的 Qt5.6.1 程序中,我必须从 QString 获取 Sha-1 散列,但我得到的结果不正确。我正在尝试使用 QCryptographicHash 库。
QString str = "ABCDEFGH";
QString hash = QString::fromStdString(QCryptographicHash::hash(str.toStdString().c_str(), QCryptographicHash::Sha1).toStdString());
// hash == "?^??[?\u0000??v??\u0015??.b??v"
在那种情况下我应该改变什么?
最佳答案
我认为这个答案对您有用,它适用于 md5 How to create MD5 hash in Qt?
尝试使用 str.toUtf8() 而不是 str.toStdString().c_str() 就像以前的答案一样
QString hash = QString("%1").arg(QString(QCryptographicHash::hash(str.toUtf8(),QCryptographicHash::Sha1).toHex()))
关于c++ - 从 QString 获取 Sha1 哈希,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37763396/