ForumsDevelopersone question about generating key!


one question about generating key!
Author Message
fobgeorge

Posted: Aug 26, 2011
Score: 0 Reference
I was according your description about how to generating the key. but I got a different from your calculation. Of course, mine doesn't work.
Please check my code, see what's wrong with it?

//----------------
//the generation is here:
//key = md5( md5(userPassword)+appToken+sessionToken );

NSString *key=[[NSString stringWithFormat:@"%@%@%@", [password md5],appToken,sessionToken]] md5];


//---------
@interface NSString (myMD5)

-(NSString*)md5;

@end

//---------
#import "myMD5.h"

@implementation NSString (myMD5)

-(NSString*)md5
{
const char *cStr = [self UTF8String];
unsigned char result[16];
CC_MD5(cStr, strlen(cStr), result);
return [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]];

}
@end


This message was edited Aug 26, 2011.
fobgeorge

Posted: Aug 26, 2011
Score: 0 Reference
dear support dept. of toodledo,
it's urgent. I am waiting for your reply.
Jake

Toodledo Founder
Posted: Aug 29, 2011
Score: 0 Reference
I am sorry, but we cannot help you debug your code. The first thing you should try is to validate your md5 function by seeing if "test" hashes to be 098f6bcd4621d373cade4e832627b4f6

If that works, then the problem is with your session or app token.
brian_1321156451

Posted: Dec 01, 2011
Score: 0 Reference
Did you ever get this resolved. I seem to be doing the same thing. The Documents show the Objective C code for both of the other 2 creations(account lookup and authentication) but dont put the code in for the key. Im sure your md5 function returns the right value for 'test' as mine does, but putting in "test" test" test" in all 3 of the Generating Keys calculator in the documentation returns a different result than doing what we are getting with this call.. ?? Is doing %@%@%@ not correct or something have to be converted to a different string type or ??

Any ideas, this should be easy but it simply doesn't work or has a fairly common mistake in working off of what documentation is given to us....
brian_1321156451

Posted: Dec 01, 2011
Score: 0 Reference
-(NSString*)md5ThisString:(NSString*)sString
{
const char *cStr = [sString UTF8String];
unsigned char result[CC_MD5_DIGEST_LENGTH];
CC_MD5(cStr, strlen(cStr), result);
NSString * md5String = [NSString stringWithFormat: @"%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X%02X", result[0], result[1], result[2], result[3], result[4], result[5], result[6], result[7], result[8], result[9], result[10], result[11], result[12], result[13], result[14], result[15]];

return md5String;
}

-(NSString*)sGetToodleKey
{
NSString * md5Password = [self md5ThisString:@"test"];

NSString* sConcat = [NSString stringWithFormat:@"%@%@%@",md5Password,@"test",@"test"];

NSString * sNewKey = [self md5ThisString:sConcat];

return sNewKey;
}


So basically, I would expect this 2nd function to return the exact same thing as the calculator for the key in the documentation if I put test,test,test in for all 3 values, but it doesnt...what am I overlooking?
brian_1321156451

Posted: Dec 01, 2011
Score: 0 Reference
FYI -

do this in the end of my function and it works

return [md5String lowercaseString];

Grrrr....


This message was edited Dec 01, 2011.
You cannot reply yet

U Back to topic home

R Post a reply

To participate in these forums, you must be signed in.