从QString获取Sha1哈希

编程入门 行业动态 更新时间:2024-10-28 04:30:30
本文介绍了从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哈希

本文发布于:2023-11-29 17:48:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1647142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:QString   哈希

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!