I've been working with C++/Qt to design a ONVIF Client, to communicate with the cameras in a given network, through XML/SOAP requests and responses.
I am currently struck trying to implement the security mechanism, for the soap requests. From the page 35 of the API guide.
We have the example..
Nonce – LKqI6G/AikKCQrN0zqZFlg==
Date – 2010-09-16T07:50:45Z
Password – userpassword
Resulting Digest – tuOSpGlFlIXsozq4HFNeeGeFLEI=
The "resulting digest" is obtained by computing this formula
Digest = B64ENCODE( SHA1( B64DECODE( Nonce ) + Date + Password ) )
I have trouble arriving at this, by using both the online tools and converter, as well as this Qt sample POC i've written.
#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);
}
Any help in this regard would be greatly appreciated.
The problem seems to be the QString storing not using UTF-8 encoding as the default.
I got it to work with this modified snippet.
Hope it helps anyone, who stumbles upon the same problem.