CCCrypt difference between iOS5 and iOS6

后端 未结 2 1871
一整个雨季
一整个雨季 2020-12-31 08:16

I have got a decryption/encryption method using CCCrypt() which worked really well on iOS5. Now I am working with the iOS6 SDK and never changed my code, but it

相关标签:
2条回答
  • 2020-12-31 08:50

    There is an apple developer forum thread discussing this issue and it has a good amount of info on the topic. It seems that the padding option is an issue for many people. Comment #11 is where the solution starts to be discussed.

    0 讨论(0)
  • 2020-12-31 09:08

    I'm not an expert i encryption, but I have the same problem and figured a workaround maybe it will be fine until some will find a real solution.

    all I did is to figure which iOS is running and for 6+ i'm changing the CCCrypt call to no padding (0 is for no padding, 1 is the enum for kCCOptionPKCS7Padding)

    float version = [[UIDevice currentDevice].systemVersion floatValue];
    if (version >= 6)
    {
        CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 0,
                                              keyPtr, kCCKeySizeAES128,
                                              ivPtr,
                                              [self bytes], dataLength,
                                              buffer, bufferSize, 
                                              &numBytesDecrypted );
    
    
        if( cryptStatus == kCCSuccess )
        {
            return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
        }
    
        free( buffer ); 
        return nil;
    }
    else
    {
        CCCryptorStatus cryptStatus = CCCrypt(kCCDecrypt, kCCAlgorithmAES128, 1,
                                              keyPtr, kCCKeySizeAES128,
                                              ivPtr,
                                              [self bytes], dataLength,
                                              buffer, bufferSize, 
                                              &numBytesDecrypted );
        if( cryptStatus == kCCSuccess )
        {
            return [NSData dataWithBytesNoCopy:buffer length:numBytesDecrypted];
        }
    
        free( buffer );
        return nil;
    }
    
    0 讨论(0)
提交回复
热议问题