What I have:
I have some images on SDcard, to be sent to a PHP server.
What I want:
I want to encrypt these images before sending to server. There will be a unique key, for every user of application, which will be used for encryption on Android Side and for decryption on PHP server side.
Please guide me how can I do this encryption and how should I send these encrypted Images to server. I can send simple images to a server (using multipart etc). But what should be the way to encrypt and then send the image to server?
I can write you some simple steps to achieve this:
Convert your image into bytes array. Read this
Convert that bytes array into Base64 string. Read this
Encrypt Base64 string using this sample code
Send the encrypted string to your server using ksoap or json
*If you reverse this process on server, you'll get your image back.
Tadaaa! :)
Related
I'm creating a PHP web service that saves files to MySql database.
The client side of my application is Android.
What is the proper way to upload a file(image, pdf, etc.) from android and save it to MySql database using PHP?
I'm not looking for codes right now, just wondering how I can do that?
The android can use the base64 to encode the img. Then you create a post http request to your php server.Your php save the base64 code to the mysql.
When you read the img.You can decode base64 to img.
Note:If you encode a img to base64 the base64 code size will bigger then img.
I need to send images from server side to client side.
If I just echo the image data, it's not safe. In the client side, I need to process and use the images (I will use these images with web unity) but I don't want the original images to be exposed.
Any help is appreciated.
Will SSL do what you need?
If you need more (to prevent snooping), check out the http://php.net/manual/en/book.mcrypt.php library: you'll need to find a corresponding decryption function in Unity. Encypt the raw image data (e.g. jpeg or png) and send over the wire; decrypt in Unity and rebuild the image.
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.
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
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
I'm uploading a image from Android to PHP server. But sometimes the image in the server is wrong (the image is not exactly the same, it is not complete).
How can I check that I upload the picture correctly?
You could send the picture size along with the picture in the POST request. Then on the server side, check the received size matches the size passed as POST param and send back an error in the response if that did not match.
More costly options would also be available:
Send the hash of the file (md5 or sha1) and check on both sides if they match
Try to read the picture in PHP and check it is a valid file
...
The best way to send an image to php(if you wish send the data without loosing it), is by encoding the image by BASE64 using POST method(I would reckon a key-value pair) for this.Then at PHP you can decode back the BASE64 String to jpeg and store it.
I want to use imgur's API to upload images however I don't want to use my server too much in the act because I'd like to keep bandwidth to a minimum.
The API accepts images in a base64 encoded string or binary.
Also if there's a way to encode images into base64 or binary in javascript that would be really useful to know too
JavaScript security restrictions prevent you from reading a local file and doing anything with it. That will be the reason that you cannot encode a file in Base64 and send it directly to that API.
Does Imgur have an API which accepts a direct file upload?