做qt还是做php,Qt / c ++相当于php例程(Qt/c++ equivalent to php routine)

Qt / c ++相当于php例程(Qt/c++ equivalent to php routine)

我在Qt中有以下代码

QString message = "somemessage";

QString key = "somekey";

QString hashed = QMessageAuthenticationCode::hash(message,

key,

QCryptographicHash::Sha256).toBase64();

它输出

8b0CA+VJBGMPVqKkygWeKuSVuquLc1vi/k9fPR8ZhXg=

在PHP我会做这样的事情:

$msg = "somemessage";

$key = "somekey";

base64_encode(hash_hmac('sha256',$msg,$key,true));

哪个输出我正在寻找的正确结果:

olsHfSnlLo5cpuBqSzfzERE3Hma0kFSo9YgCacOqCCw=

难道我做错了什么?

I have the following code in Qt

QString message = "somemessage";

QString key = "somekey";

QString hashed = QMessageAuthenticationCode::hash(message,

key,

QCryptographicHash::Sha256).toBase64();

It outputs

8b0CA+VJBGMPVqKkygWeKuSVuquLc1vi/k9fPR8ZhXg=

In php I would do something like this:

$msg = "somemessage";

$key = "somekey";

base64_encode(hash_hmac('sha256',$msg,$key,true));

Which outputs the correct result I'm looking for:

olsHfSnlLo5cpuBqSzfzERE3Hma0kFSo9YgCacOqCCw=

Am I doing something wrong?

原文:https://stackoverflow.com/questions/24348080

2020-01-13 12:01

满意答案

QMessageAuthenticationCode的 Qt文档说参数应该在QByteArray中。 您是如何设法编译此代码的? 我用你的代码编写了一个小程序(用于Qt),并设法得到了与php代码相同的结果。 php代码结果

这段代码给出了与上面的php代码结果相同的结果。

QByteArray ke = "somekey";

QByteArray msg = "somemessage";

QString hashed = QMessageAuthenticationCode::hash(msg,

ke,

QCryptographicHash::Sha256).toBase64();

qDebug() << hashed;

Qt documentation for QMessageAuthenticationCode says the parameters should be in QByteArray. How did you even manage to get this code compiled? I wrote a small program with your code (for Qt) and managed to get the same result for the php code too. php code result

This piece of code gives me the same result as the above php code result.

QByteArray ke = "somekey";

QByteArray msg = "somemessage";

QString hashed = QMessageAuthenticationCode::hash(msg,

ke,

QCryptographicHash::Sha256).toBase64();

qDebug() << hashed;

2014-06-22

相关问答

您可以将字符代码直接写入文件: fputs($fp, "\x10");

// or

fputs($fp, chr(16));

// or

fputs($fp, chr(hexdec(10));

You can write the character code directly to the file: fputs($fp, "\x10");

// or

fputs($fp, chr(16));

// or

fputs($fp, chr(hexdec(10));

怎么了? 你的a是一个QString ,它的成员函数QString::at()总是返回QChar 。 据我所知,C ++中的std::string::at()也会返回char而不是int 。 C ++ / Qt中的数据类型必须认真对待! 因此,返回的QChar需要首先翻译为int ,以符合QVector模板的类型。 但不用担心, QChar有一个成员函数: QChar::digitValue ( 返回数字的数字值,如果该字符不是数字,则返回-1 )。 解: 尝试out.push_back...

你很挑剔。 返回字符串的任何函数都将具有声明,填充和返回的字符串变量,就像您已经编写的函数一样。 此外,“命名返回值优化”允许编译器有时忽略额外变量。 调用者将为对象分配空间并将其传递给您的函数,在该函数中它将被修改,就好像它是rtn变量一样; 返回时不会复制,因为该值已在所需位置。 You're being picky. Any function that returns a string is going to have a string variable that's declared, f...

QTextStream提供了标准库流的等价物。 不要忘记,文本流应该在字符串之前销毁。 QString mystring = "67 49 213 59";

QTextStream myteststream(&mystring);

int a = 0, b = 0, c = 0, d = 0;

myteststream >> a >> b >> c >> d;

QTextStream provides the equivalent of the standard library's stream...

如果您使用的是QListWidget而不是QListView ,那么您可以执行以下操作: 听取信号: QListWidget::itemPressed ( QListWidgetItem * item )而不是表示项目已更改的信号(即currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous )在我的示例中为currentItemChanged ( QListWidgetItem * current, QLi...

qt.inline取决于Qt。 假设您在系统中安装了Qt,错误建议您没有指定Qt的安装位置。 在使用find_package(Qt5 ...)的“普通”项目中,您可以完成: cmake .. -D Qt5_DIR=/path/to/qt -G "Sublime Text 2 - Ninja"

其中/path/to/qt是Qt安装中包含Qt5Config.cmake的目录。 鉴于是您的Qt安装的根目录,这应该是/lib/cmake/Qt5 。 qt.inline更具...

这可能是之前已经回答过的,请查看之前的帖子,看看是否有帮助: C#构建十六进制表示法字符串 This may have been previously answered, check this previous post out to see if it helps: C# Build hexadecimal notation string

它被称为QGroupBox : 您可以通过GUI编辑器(我的首选方法)创建它,也可以在Python中创建一个QGroupBox()对象并将其添加到窗口的布局中。 It's called a QGroupBox: You can either create it via a GUI editor (my preferred method), or you can create a QGroupBox() object in Python and add it to your window's lay...

QMessageAuthenticationCode的 Qt文档说参数应该在QByteArray中。 您是如何设法编译此代码的? 我用你的代码编写了一个小程序(用于Qt),并设法得到了与php代码相同的结果。 php代码结果 这段代码给出了与上面的php代码结果相同的结果。 QByteArray ke = "somekey";

QByteArray msg = "somemessage";

QString hashed = QMessageAuthenticationCode::hash(msg,...

相关文章

PHP PHP是运行在服务器端的脚本,可以运行在UNIX、LINUX、WINDOWS、Mac OS下

...

php中文字符串长度及定长截取问题使用str_len("中国") 结果为6,php

...

背景:项目中需要将原有的sphinx搜索引擎换成solr,以下是通过参照网络内容后,从搭建到调用的一次

...

1、有一个word.txt文件,里边存的是类似于单词库(英语),一个单词独占一行。然后让你写一个长须实

...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值