Question

i happen to be getting varying outputs when i call the digest method (in java) and CC_SHA1 (in Objective-c multiple times.

Please note that when the loop isn't used, i'm getting matching outputs.

The following are the implementations i'm currently employing.

Objective C Snippet

NSString *haha= [NSString stringWithFormat:@"%@%@",sPassPhrase,sSaltValue];
NSData *abKey0 = [haha dataUsingEncoding:NSASCIIStringEncoding];
NSMutableData *abKey = [NSMutableData dataWithData:abKey0];

unsigned char digest[20];
for(int i=1;i<iIterations;i++)
{
    CC_SHA1(abKey.bytes, abKey.length, digest);
    abKey = [NSMutableData dataWithBytes:digest length:20];
}

Java snippet

String haha = sPassPhrase + sSaltValue;
byte[] abKey = haha.getBytes("US-ASCII");
MessageDigest oSHA1 = MessageDigest.getInstance("SHA-1");

for (int i = 1; i <= iIterations; i++) 
{
    abKey = oSHA1.digest(abKey);
}

This has me scouring the api docs for several hours now but i'm not able to find anything helpful.

Was it helpful?

Solution

One obvious differences is that you are doing one iteration less in objective C than you are doing in Java. Look at the '<' versus "<=' in the two for loops.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top