I have a large piece of text which I have encrypted using Rijndael 128 CBC mode and encoded using base64 in PHP (see code below). This data is posted onto a webpage which is then downloaded by my app:
<?php
$keyT = "keyString";
$key = md5($key);
$key_size = strlen($key);
$plaintext = "Text_Block";
$iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
$iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
$ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,
$plaintext, MCRYPT_MODE_CBC, $iv);
# prepend the IV
$ciphertext = $iv . $ciphertext;
# encode using base64
$ciphertext_base64 = base64_encode($ciphertext);
$data = $ciphertext_base64;
?>
Using <NSURLConnectionDataDelegate>
I have set up a protocol that downloads the encrypted and encoded data into `downloadData (NSMutableData). Then in the -(void) connectionDidFinishLoading:(NSURLConnection *) connection I have:
-(void) connectionDidFinishLoading:(NSURLConnection *) connection {
NSLog(@"Succesfully downloaded data! received %d bytes.", [downloadData length]);
NSString *dataText = [[NSString alloc] initWithData:downloadData encoding:NSUTF8StringEncoding];
NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:dataText options:0];
// Now lets say I have the key created in the php file:
char void *key = @"key goes here";
// This is where it stops for me, how do I extract the IV (which should be the first 16 characters) and how do I use this to decrypt the data?
}