CCCrypt崩溃与EXC_BAD_ACCESS

时间:2013-11-25 16:58:46

标签: ios cryptography exc-bad-access commoncrypto ecb

我正在加密视频,有时我会遇到CCCrypt的崩溃。 这是我的加密方法,任何人都可以解释为什么它会崩溃? (该过程在队列中的NSOperation中运行)。崩溃发生在CCCryptorStatus cryptStatus = CCCrypt

    char *key = MY_ENCRYPTION_KEY;
    NSUInteger dataLength = [data length];
    uint8_t encryptedData[dataLength + kCCBlockSizeAES128];
    size_t encryptedLength;
    size_t encryptedDataLength = dataLength + kCCBlockSizeAES128;
    CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt, kCCAlgorithmAES128, kCCOptionECBMode|kCCOptionPKCS7Padding, key, kCCKeySizeAES128, NULL, [data bytes], dataLength, encryptedData, encryptedDataLength, &encryptedLength);

    if(cryptStatus == kCCSuccess)
    {
        NSData *output = [[NSData alloc] initWithBytes:encryptedData length:encryptedLength];

        completionBlock(nil, output);

    } else {
        NSError *error = [[NSError alloc] initWithDomain:@"Error encrypting" code:-999 userInfo:nil];
        completionBlock(error, nil);
    }

0 个答案:

没有答案