Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 无法复制Onvif API示例的SHA1和Base64输出_C++_Qt_Security_Authentication_Onvif - Fatal编程技术网

C++ 无法复制Onvif API示例的SHA1和Base64输出

C++ 无法复制Onvif API示例的SHA1和Base64输出,c++,qt,security,authentication,onvif,C++,Qt,Security,Authentication,Onvif,我一直在使用C++/Qt设计一个ONVIF客户端,通过XML/SOAP请求和响应与给定网络中的摄像机进行通信 我目前正在尝试为soap请求实现安全机制。 从的第35页 我们有这个例子 Nonce–LKqI6G/AikKCQrN0zqZFlg== 日期–2010-09-16T07:50:45Z 密码–用户密码 结果摘要–TuosPGLFILIXSOZQ4HFNEEGEFLEI= “结果摘要”通过计算此公式获得 摘要=B64编码(SHA1(B64解码(暂时)+日期+密码)) 通过使用在线工具和转换器

我一直在使用C++/Qt设计一个ONVIF客户端,通过XML/SOAP请求和响应与给定网络中的摄像机进行通信

我目前正在尝试为soap请求实现安全机制。 从的第35页

我们有这个例子

Nonce–LKqI6G/AikKCQrN0zqZFlg==
日期–2010-09-16T07:50:45Z
密码–用户密码
结果摘要–TuosPGLFILIXSOZQ4HFNEEGEFLEI=

“结果摘要”通过计算此公式获得

摘要=B64编码(SHA1(B64解码(暂时)+日期+密码))

通过使用在线工具和转换器,以及我编写的Qt示例POC,我很难做到这一点

#include <QCoreApplication>
#include <QString>
#include <QCryptographicHash>
#include <QDebug>

QString base64_encode(QString string);
QString base64_decode(QString string);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString nonce ="LKqI6G/AikKCQrN0zqZFlg==";
    QString date = "2010-09-16T07:50:45Z";
    QString pass = "userpassword";

    QString nonce_dec = base64_decode(nonce);

    QString res = nonce_dec+date+pass;
    QByteArray resBytes(res.toStdString().c_str());
    QCryptographicHash sha(QCryptographicHash::Sha1);
    sha.addData(resBytes);
    qDebug()<<"Resultant Hash is ";
    QString resHash = base64_encode(sha.result());
    qDebug()<<resHash ;

    return a.exec();
}

QString base64_encode(QString string){
    QByteArray ba;
    ba.append(string);
    return ba.toBase64();
}

QString base64_decode(QString string){
    QByteArray ba;
    ba.append(string);
    return QByteArray::fromBase64(ba);
}
#包括
#包括
#包括
#包括
QString base64_编码(QString字符串);
QString base64_解码(QString字符串);
int main(int argc,char*argv[])
{
qcorea应用程序(argc、argv);
QString nonce=“LKqI6G/aikkqqrn0zqzflg=”;
QString date=“2010-09-16T07:50:45Z”;
QString pass=“userpassword”;
QString nonce_dec=base64_解码(nonce);
QString res=当前12月+日期+通行证;
QByteArray resBytes(res.toStdString().c_str());
qcryptographicshash-sha(qcryptographicshash::Sha1);
sha.addData(resBytes);

qDebug()问题似乎是QString存储未使用UTF-8编码作为默认值

我用它来处理这个修改过的代码片段

#include <QCoreApplication>
#include <QString>
#include <QCryptographicHash>
#include <QDebug>

QString base64_encode(QByteArray ba);
QByteArray base64_decode(QByteArray ba);

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    QString nonce ="LKqI6G/AikKCQrN0zqZFlg==";
    QString date = "2010-09-16T07:50:45Z";
    QString pass = "userpassword";   

    QByteArray nonce_dec = base64_decode(nonce.toUtf8());

    QByteArray res = nonce_dec+QByteArray(date.toUtf8())+QByteArray(pass.toUtf8());
    QByteArray resBytes(res.toStdString().c_str());
    QCryptographicHash sha(QCryptographicHash::Sha1);
    sha.addData(resBytes);
    QByteArray shaBytes = sha.result();
    qDebug()<<"Resulting Hash is ";
    QString resHash = base64_encode(shaBytes);    
    qDebug()<<resHash ;
    return a.exec();
}

QString base64_encode(QByteArray ba){
    return ba.toBase64();
}

QByteArray base64_decode(QByteArray ba){
    return QByteArray::fromBase64(ba);
}
#包括
#包括
#包括
#包括
QString base64_编码(QByteArray-ba);
QByteArray base64_解码(QByteArray ba);
int main(int argc,char*argv[])
{
qcorea应用程序(argc、argv);
QString nonce=“LKqI6G/aikkqqrn0zqzflg=”;
QString date=“2010-09-16T07:50:45Z”;
QString pass=“userpassword”;
QByteArray nonce_dec=base64_解码(nonce.toUtf8());
QByteArray res=nonce_dec+QByteArray(date.toUtf8())+QByteArray(pass.toUtf8());
QByteArray resBytes(res.toStdString().c_str());
qcryptographicshash-sha(qcryptographicshash::Sha1);
sha.addData(resBytes);
QByteArray shaBytes=sha.result();
qDebug()