使用Qt生成MD5哈希 [英] Generating a MD5 Hash with Qt

查看:199
本文介绍了使用Qt生成MD5哈希的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Qt生成MD5哈希.我生成的哈希值必须与使用其他语言(例如PHP)生成的其他标准MD5哈希值兼容.

I am trying to generate an MD5 hash with Qt. The hash I generate needs to be compatible with other standard MD5 hashes generated with other languages such as PHP.

这段代码没有给我想要的结果:

This code does not give me the desired results:

QString encodedPass = QString(QCryptographicHash::hash(("myPassword"),QCryptographicHash::Md5));

结果是Þ±SoHu÷Õ?!?××L",而不是"deb1536f480475f7d593219aa1afd74c".有人可以告诉我我在做什么错吗?

The result is "Þ±SoHu÷Õ?!?¡¯×L" instead of "deb1536f480475f7d593219aa1afd74c". Can someone show me what I am doing wrong?

推荐答案

PHP以十六进制形式提供给您,Qt以二进制形式提供给您.使用 QByteArray::toHex 将其转换为十六进制.

PHP gives it to you in hex, Qt in binary. Convert it to hex using QByteArray::toHex.

QString blah = QString(QCryptographicHash::hash(("myPassword"),QCryptographicHash::Md5).toHex())

这篇关于使用Qt生成MD5哈希的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆