Advertisement
Guest User

Untitled

a guest
Sep 20th, 2014
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. <?php
  2. $keyT = "keyString";
  3. $key = md5($key);
  4. $key_size = strlen($key);
  5. $plaintext = "Text_Block";
  6.  
  7. $iv_size = mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC);
  8. $iv = mcrypt_create_iv($iv_size, MCRYPT_RAND);
  9.  
  10. $ciphertext = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key,
  11. $plaintext, MCRYPT_MODE_CBC, $iv);
  12.  
  13. # prepend the IV
  14. $ciphertext = $iv . $ciphertext;
  15.  
  16. # encode using base64
  17. $ciphertext_base64 = base64_encode($ciphertext);
  18.  
  19. $data = $ciphertext_base64;
  20. ?>
  21.  
  22. -(void) connectionDidFinishLoading:(NSURLConnection *) connection {
  23. NSLog(@"Succesfully downloaded data! received %d bytes.", [downloadData length]);
  24. NSString *dataText = [[NSString alloc] initWithData:downloadData encoding:NSUTF8StringEncoding];
  25. NSData *decodedData = [[NSData alloc] initWithBase64EncodedString:dataText options:0];
  26. // Now lets say I have the key created in the php file:
  27. char void *key = @"key goes here";
  28. // 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?
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement