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
Contributor
Posts: 12
Registered: ‎02-19-2013
My Device: Z10
My Carrier: 123456789

getting wrong hash/digest value using SHA1 algorithm

I tried to create the hash key using SHA1 algorithm using Security Builder APIs. I can able to create the digest, but its not expected result. I dont know where exactly I am doing wrong. below is the code.

 

 

    sb_GlobalCtx globalCtx;
    sb_Context hashContext;

    unsigned char messageData[4] = "abc";
    unsigned char digest[40];
    hu_GlobalCtxCreateDefault(&globalCtx);

    int result = hu_RegisterSbg56(globalCtx);
    int seedResult = hu_RegisterSystemSeed(globalCtx);
    int initResult = hu_InitSbg56(globalCtx);
    int sha1Return =  hu_SHA1Begin(SB_SHA1_DIGEST_LEN, NULL, &hashContext, globalCtx);
    int hashResult = hu_SHA1Hash(hashContext, 4, messageData, globalCtx);
    int digestResult = hu_SHA1DigestGet(hashContext, digest, globalCtx);

 

actually digest should contain "a9993e364706816aba3e25717850c26c9cd0d89d", but I am getting different value.

can some one help on this?

Highlighted
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: getting wrong hash/digest value using SHA1 algorithm

Hi,
Message length of 4 includes zero-terminator, is this intended? Maybe 3 will produce the expected result.

Andrey Fidrya, @zmeyc on twitter