문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top