本文介绍了从QString获取Sha1哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的Qt5.6.1程序中,我必须从QString中获取Sha-1哈希,但结果却不正确.我正在尝试使用QCryptographicHash库.
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?
推荐答案我认为此答案对您有用,它适用于md5 如何在Qt中创建MD5哈希?
I think this answer will be useful for you it is for md5 How to create MD5 hash in Qt?
代替str.toStdString().c_str()尝试使用str.toUtf8() 像这样以前的答案
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()))更多推荐
从QString获取Sha1哈希
发布评论