It's a funny coincident that I need to do some work based on OAUTH open protocol again.But according to the qoauth libs implementation and the previous blog I mentioned,there is a need for me to make it with little code change for different platform(on Desktop I need to compile and import QCA libraries in addition to qca-ossl-plugin see below on that page,on Symbian I need to import hash.lib by using related class CSHA1,CMAC).Hum,is there a better solution for me to utilize to make it easier?
So I think it's time to play a small trick.My proposal is that do HMAC-SHA1 in app without any change to fit all platform with Qt(Desktop,embed,mobile device).The main idea is that making HMAC-SHA1 scriptable in apps.
The step as following.
1.Please check http://pajhome.org.uk/crypt/md5/sha1.html and import sha1.js in your project.
2.QtScript module provides powerful embedded scripting environment through the QtScript classes.So we can call a Qt script function from C++ like this.
... ... QFile file("./sha1.js"); file.open(QIODevice::ReadOnly); QString jsContent = QString::append(file.readAll()); file.close(); .... .... QScriptEngine engine; engine.evaluate(jsContent);// very similar with function QWebFrame::evaluateJavaScript () QScriptValue value = engine.globalObject(); QScriptValueList paramList; paramList<<key<<baseString; QString result = value.property("b64_hmac_sha1").call(QStringValue(),valueList).toString() //call js function b64_hmac_sha1 from C++ and result is what you want. ;)
Ps:
special present from Finland before my birthday.
can't wait to test it.
I will be waiting impatiently for the time when I get it.
没有评论:
发表评论