1

I've been using this code to upload an image : how to post an image to the web server and it works fine.

My question is : is there a way to aes-256 encrypt the image with a passphrase before sending it and decrypting it with php on the server? It's like using these functions : AES Encryption for an NSString on the iPhone but instead of NSString, NSData.

Any help would be useful.

Community
  • 1
  • 1

2 Answers2

1

To my idea from iOS

you convert image to base64 string using this link

Now encrypt this string int AES264 using this link

On php side

Decrypt using this link

Decode base64 string using this link

Community
  • 1
  • 1
Paresh Navadiya
  • 38,095
  • 11
  • 81
  • 132
0

http://highaltitudehacks.com/2013/09/26/ios-dev-encrypted-images-and-saving-them-in-app-sandbox/

this is how you achieve image encryption of images in iOS (one way at least) you can then simply post the result. but you have to find a way to exchange your encryption key. It would not be clever to simply send your keys within the same request... and if so you should at least use https

Soulan
  • 341
  • 1
  • 6
  • okay that's on the client side, how would i decrypt it on the server with php ? – user3981459 Aug 27 '14 at 06:45
  • keep in mind that after decrypting you have a binary representation of your image, you can either write it down to a file, or open it with gd, but you should preserve the image type if you don't want to make a manual detection of it's mime – Soulan Aug 27 '14 at 07:24
  • i was thinking of doing this : move_uploaded_file(sqAES::decrypt('password',$_FILES['userfile']['tmp_name']), $uploadfile); wouldn't that solve the problem ? – user3981459 Aug 27 '14 at 07:33
  • this will not work, because you can not move and decrypt the file like this... you should read the file contents, decrypt it and save it to your target location – Soulan Aug 27 '14 at 07:35
  • so i should do this : $decryptedfile = sqAES::decrypt('password',$_FILES['userfile']['tmp_name']); then this : move_uploaded_file($decryptedfile, $uploadfile); ? – user3981459 Aug 27 '14 at 07:39
  • sorry but i'm very new to encryption and decryption, never used it – user3981459 Aug 27 '14 at 07:43
  • $decryptedfile = sqAES::decrypt('password',file_get_contents($_FILES['userfile']['tmp_name'])); and then file_put_contents($targetfile, $decryptedfile); keep in midn that you have to take the sgAES class from the php.net example to get this to wkr – Soulan Aug 27 '14 at 07:44
  • it is not a problem that you are new don't worry ;) everyone needs to start somewhere.. the problem is not the encryption itself, it is more the side conditions that can make your life hard :D – Soulan Aug 27 '14 at 07:47
  • where exactly did you struggle? – Soulan Aug 27 '14 at 13:14