应用程序因错误而崩溃;无效指针从可用列表中退出队列;在Objective-C中
当我们为AES加密/解密生成密钥时,出现以下错误应用程序因错误而崩溃;无效指针从可用列表中退出队列;在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];
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)
?