I am trying to decrypt data in ios which was encrypted in Java. Following is the code:
+(NSString*) decryptData:(NSString*) data:( NSData*) passKey {
NSString * strKey = [Base64Util encodeBase64WithData:passKey];
NSLog( @" decryption key: %@" ,strKey);
//decrypt `data
NSData * nsData = [Base64Util decodeBase64WithString:data];
NSLog(@"here 1: %@",nsData);
size_t numOfBytesDecrypted;
size_t bufferSize = nsData.length + kCCBlockSizeAES128;
NSMutableData * buffer = [NSMutableData dataWithLength:bufferSize];
CCCrypt(kCCDecrypt, kCCKeySizeAES128, kCCOptionECBMode , derivedKey.bytes, derivedKey.length, Nil , passCodeData.bytes, passCodeData.length, buffer. mutableBytes, bufferSize, &numOfBytesDecrypted);
return [NSData dataWithBytesNoCopy:buffer. mutableBytes length :numOfBytesDecrypted];
}
But when the function CCCrypt executes, it throws up an EXC_BAD_ACCESS code 2. I have ARC enabled. I am unable to find the cause of the error. An help would be appreciated.
Really silly of me.
The second parameter should be
kCCAlgorithmAES128