I'm trying to encrypt a json in AES256 in objective C to send to one server and php decrypt it using the following line:
MCRYPT_DECRYPT (MCRYPT_RIJNDAEL_256, $ key, base64_decode ($ ha), MCRYPT_MODE_ECB, NULL));
took several days searching and testing and I have not gotten results. The code I'm using is this:
- (NSString *)AES256EncryptData:(NSData *) datos {
//NSData * datos = [json dataUsingEncoding:NSUTF8StringEncoding];
UIApplication *aplicacion = [UIApplication sharedApplication];
AppDelegate *delegate = (AppDelegate *) aplicacion.delegate;
char keyPtr[kCCKeySizeAES256+1];
bzero(keyPtr, sizeof(keyPtr));
[delegate.appKey getCString:keyPtr maxLength:sizeof(keyPtr) encoding:NSUTF8StringEncoding ];
NSUInteger dataLength = [datos length];
size_t bufferSize = dataLength + kCCBlockSizeAES128;
void *buffer = malloc(bufferSize);
size_t numBytesEncrypted;
CCCryptorStatus cryptStatus = CCCrypt(kCCEncrypt,
kCCAlgorithmAES128,
kCCOptionECBMode + kCCOptionPKCS7Padding,
keyPtr,
kCCKeySizeAES256,
NULL,
[datos bytes],
[datos length],
buffer,
bufferSize,
&numBytesEncrypted);
if (cryptStatus == kCCSuccess) {
NSData *returnData = [[NSData alloc] initWithBytes:buffer length:numBytesEncrypted];
return [returnData base64EncodedStringWithOptions:0];
}
free(buffer);
return nil;
}