2010年4月17日星期六

Using HMAC-SHA1 in qOAuth on Symbian

In the wake of qDou 0.2.5 release,I am working on Deploying qDou on Sybmain recently,But I am sorry about.........;-( I must admit I am a rookie on Symbian,irrespective Of  playing with Symbiam Os phone,or Development on Symbian Os.To take trial instance how scornful I was when using a 3250,I thought that it was just phone with colorful push buttons that can make happy noise and it was just a practical tools for accessing family,friends and business associats (maybe in the future,Because I am an undergraduate still now ).Upon a careful study these days,I learn a lot on Symbian development,really,Or at least To a rookie.When I look back,I just feel funny.So I change my mind.Symbian is Strong.
Back to the topic,becouse qDou release depends on qOAuth and oAuth request using the HMAC-SHA1 signature method.
On the Windows or linux,In order to do that
the following steps are
1. build OpenSSL 0.9.6+
2. build qca-2.0.0
3. build the qca plugin for OpenSSL (the Capabilities of qca-ossl contains HMAC_SHA1)?
4. build qOAuth
But on the Symbian,as a result of different platform,you will have a lot of work to do.
even though you achieved,Maybe It doesn't work at last and you will get into trouble when deploy your apps on Symbian.em.........There is a easy way,Look this.
How to generate oauth signature using HMAC-SHA1 in Symbian C++
Follow These Tips .
we just need to do little stuff
1.add macro Q_OS_SYMBIAN to remove anything about QCA from *.cpp or *.h in qOAuth when Precompiled
2.generating your own random number method to replace the following codes
QCA::InitializationVector iv( 16 );
QByteArray nonce = iv.toByteArray().toHex();
3.add these lines in function:createSignature
#ifdnef Q_OS_SYMBIAN
.....
.....
.....
#else 

CSHA1* sha=CSHA1::NewL();
TBuf8<100> keyVal;
keyVal.Copy(_L8(QByteArray(consumerSecret + "&" + tokenSecret).constData()));
CHMAC* hmac=CHMAC::NewL(keyVal,sha);
TBuf8<1024> baseString;
TPtrC8 hashedSig(hmac->Hash(baseString));
TImCodecB64 b64enc;
b64enc.Initialise();
HBufC8* buf = HBufC8::NewL(hashedSig.Length() * 2);
buf->Des().Copy(hashedSig);
TBuf8<512> result;
b64enc.Encode(buf->Des(),result);
result.Copy(result.Left(result.Length()));
if(hmac)
{
    delete hmac;
    hmac=NULL;
}
digest = QByteArray::fromRawData((char*)result.Ptr(),result.Length());
#endif
It's very easy right?
hope this is useful for thoses like me who want to use qOauth on Symbian
see you.