Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
应用程序因错误而崩溃;无效指针从可用列表中退出队列;在Objective-C中_Objective C_Commoncrypto - Fatal编程技术网

应用程序因错误而崩溃;无效指针从可用列表中退出队列;在Objective-C中

应用程序因错误而崩溃;无效指针从可用列表中退出队列;在Objective-C中,objective-c,commoncrypto,Objective C,Commoncrypto,当我们为AES加密/解密生成密钥时,出现以下错误 malloc: *** error for object 0x1c421b840: Invalid pointer dequeued from free list *** set a breakpoint in malloc_error_break to debug 下面添加了生成密钥的代码: - (NSData*)generateKey:(NSString*)childKey { unsigned char saltChar[16];

当我们为AES加密/解密生成密钥时,出现以下错误

malloc: *** error for object 0x1c421b840: Invalid pointer dequeued from free list
*** set a breakpoint in malloc_error_break to debug
下面添加了生成密钥的代码:

- (NSData*)generateKey:(NSString*)childKey {
    unsigned char saltChar[16];
    for (int i=0; i<16; i++) {
        saltChar[i] = 0;
    }
    NSData *salt = [NSData dataWithBytes:saltChar length:16];
    size_t bufferSize =  kCCBlockSizeAES128;
    void *buffer = malloc(bufferSize);
    int result = CCKeyDerivationPBKDF(kCCPBKDF2,            // algorithm
                                      childKey.UTF8String,  // password
                                      [childKey lengthOfBytesUsingEncoding:NSUTF8StringEncoding],  // passwordLength
                                      salt.bytes,           // salt
                                      salt.length,          // saltLen
                                      kCCPRFHmacAlgSHA1,    // PRF
                                      65,         // rounds
                                      buffer, // derivedKey
                                      bufferSize*8); // derivedKeyLen

    NSLog(@"Unable to create AES key for password: %d", result);
    NSData *data = nil;
    if (result == kCCSuccess) {
        data = [[NSData alloc] initWithData:[NSData dataWithBytesNoCopy:buffer length:16]];
    }
    free(buffer);
    return data;
}
-(NSData*)generateKey:(NSString*)childKey{
无符号字符saltChar[16];

对于(int i=0;我是否尝试添加AES加密/解密功能?是@Faysalahmed检查此:
bufferSize*8
?但您仅分配
malloc(bufferSize)
dataWithBytesNoCopy:buffer
空闲(buffer)