문제

The following worked just fine with iOS5 as the base class but fails (SIGABRT) with iOS6. Could it be an OS thing or an architecture thing?

Important to also note is the accompanying MD5 hash does work.

-(NSString *)SHA1Hash {
    const char *cStr = [self UTF8String];
    unsigned char digest[16];
    CC_SHA1( cStr, strlen(cStr), digest ); // This is the sha1 call

    NSMutableString *output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2];

    for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++)
        [output appendFormat:@"%02x", digest[i]];

    return output;
}

Thanks for any and all help!

도움이 되었습니까?

해결책

You were probably getting "lucky" on iOS 5. SHA-1 digests are 20 bytes, not 16:

unsigned char digest[16];

다른 팁

Use the macro CC_SHA1_DIGEST_LENGTH to declare your digest length. 16 is too short so you are trashing the stack.

unsigned char digest[CC_SHA1_DIGEST_LENGTH];

From man page for CC_SHA1

CC_SHA1() computes the SHA-1 message digest of the len bytes at data and places it in md (which must have space for CC_SHA1_DIGEST_LENGTH == 20 bytes of output). It returns the md pointer.

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