I am new in android.I want to encrypt a file and I want to decrypt it an show it in a image view can anyone help me. I have no idea about the encryption and decryption.
Asked
Active
Viewed 800 times
0
-
What are your security requirements/threat model? Do you want to avoid the image being sniffed when it is transferred to some other device or do you want it to just never be stored unencrypted so someone with physical access can't read it without some password? Where is the image from? Is it created on the device? Is it transferred encrypted from somewhere else? – perelman Feb 13 '12 at 04:53
-
I have an image in sdcard I want to encrypt it and the same image I want to decrypt it and write it to an image view.there is no high security requirements. I just want a simple encryption and decryption method.when I decrypt it it should not be saved on the disk. – Sreedev Feb 13 '12 at 05:02
-
@SreedevR which algorithm u used for image encryption and decryption ? – Erum Dec 18 '14 at 04:57
1 Answers
2
If you have a File
of the file on the SD card, you can read it into a byte[]
, and do realImageContents = decrypt(fileContents)
for some function decrypt()
. Then you can get a Bitmap
object using BitmapFactory
and pass that to ImageView.setImageBitmap()
.
Look at javax.crypto for using actual encryption algorithms. If you just want to obfuscate the image, you could just write your own encrypt()
/decrypt()
that does something simple like an XOR cipher with the key hard-coded in your application.
-
Which part are you having trouble with? I linked to you to code samples for most of the steps and gave you the search keywords for handling encryption in Java. One of the "Related" links I see is [Android - encryption and decryption](http://stackoverflow.com/q/5524018/1124792) which has a link to [How to encrypt and decrypt strings?](http://www.tutorials-android.com/learn/How_to_encrypt_and_decrypt_strings.rhtml) in a comment (it does the actual work on `byte[]`s so you can just remove the conversions to/from `String`). – perelman Feb 13 '12 at 05:55
-
@SreedevR have u resolve your issue ? can u pls share.I m following code this is not working here is the link http://stackoverflow.com/questions/12136558/encryption-and-decryption-of-image-file?rq=1 – Erum Dec 23 '14 at 07:02