Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Developer
Developer
Posts: 60
Registered: ‎04-14-2014
My Device: z10
My Carrier: Digitel
Accepted Solution

HMAC-SHA1 Problem!

[ Edited ]

I dont understand this problem! I'm really frustrated...

 

I have this function por HMAC-SHA1:

 

QByteArray Fla**bleep**::firmaHMACSHA1(QString textBase, QString key) {
     qDebug() << "Base: " + textBase;
     qDebug() << "key: " + key;
     sb_Context hmacContext;
     sb_GlobalCtx globalCtx;
     unsigned char messageDigestHMAC[SB_HMAC_SHA1_160_TAG_LEN];

     hu_GlobalCtxCreateDefault(&globalCtx);
     hu_RegisterSbg56(globalCtx);
     //hu_RegisterSystemSeed(globalCtx);
     hu_InitSbg56(globalCtx);

 

     QByteArray textBaseBytes = textBase.toUtf8();
     unsigned char* textBaseHash = reinterpret_cast<unsigned char*>(textBaseBytes.data());
     QByteArray keyBytes = key.toUtf8();
     unsigned char* keyHash = reinterpret_cast<unsigned char*>(keyBytes.data());

 

     hu_HMACSHA1Begin(SB_HMAC_SHA1_160_TAG_LEN, keyHash, NULL, &hmacContext, globalCtx);
     hu_HMACSHA1Hash(hmacContext, (size_t) textBaseBytes.length(), textBaseHash, globalCtx);
     hu_HMACSHA1End(&hmacContext, SB_HMAC_SHA1_160_TAG_LEN, messageDigestHMAC, globalCtx);

 

     QByteArray passwordHash = QByteArray::fromRawData(reinterpret_cast<const char *>(messageDigestHMAC), SB_HMAC_SHA1_160_TAG_LEN);

     hu_GlobalCtxDestroy(&globalCtx);
     qDebug() << passwordHash.toBase64();
     return passwordHash.toBase64().toPercentEncoding();
}

 

For this values, working GOOD:

 

textBase: POST&https%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Frequest_token&oauth_callback%3Dhttp%253A%252F%252Fwww.poncholabs.net%26oauth_consumer_key%ca93486d3aa617636656d7XXXXXXXXXX%26oauth_nonce%3D87ae6fb631f7c8a627e8e28785d9992d%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1402195208%26oauth_version%3D1.0


key: f0e54c70825XXXXX&

 

But, for this values dont work:

 

textBase: POST&https%3A%2F%2Fwww.flickr.com%2Fservices%2Foauth%2Faccess_token&oauth_consumer_key%3Dca93486d3aa617636656d7XXXXXXXXXX%26oauth_nonce%3D936a40b7e8eea0dc537e5f2edee1387a%26oauth_signature_method%3DHMAC-SHA1%26oauth_timestamp%3D1402195228%26oauth_token%3D72157644652600637-4d9daa97cdab0be3%26oauth_verifier%3D7ee06a20ebc9d621%26oauth_version%3D1.0


key: f0e54c70825XXXXX&dcec3a2abb77844b

 

Why not work well? For comparing the generated hash with the result https://quickhash.com, are NOT the same (for the first values placed if I coincide).

 

You can see that between the values I put, what changes is basically the key

 

NOTE: For obvious reasons I have NOT placed the secret values of the full API, I have replaced some characters with 'X'

 

Please help. :smileyfrustrated:

My Answer is good? Nice! Please, Clicked the "Thanks" button, this is very helpful for me! :smileyhappy:
Mi respuesta es buena? Que bien! Por favor, haz clic en el botón "Gracias", esto es muy útil para mí! :smileyhappy:
Developer
Developer
Posts: 60
Registered: ‎04-14-2014
My Device: z10
My Carrier: Digitel

Re: HMAC-SHA1 Problem!

SOLVE:

 

Change hu_HMACSHA1Begin(SB_HMAC_SHA1_160_TAG_LEN, keyHash, NULL, &hmacContext, globalCtx);

 

By: hu_HMACSHA1Begin((size_t) keyBytes.length(), keyHash, NULL, &hmacContext, globalCtx);

 

Is the correct. :smileyhappy:

My Answer is good? Nice! Please, Clicked the "Thanks" button, this is very helpful for me! :smileyhappy:
Mi respuesta es buena? Que bien! Por favor, haz clic en el botón "Gracias", esto es muy útil para mí! :smileyhappy: