0

I have folder named docFolder located inside download directory of device interval memory. The folder contains lot of files in different format (html,png,jpg etc...).

How can I easily programmatically encrypt docFolder so that users can not open the folder. I also need to decrypt docFolder programmatically so that I can use the files in my code.

Please help.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
  • you can follow this one https://stackoverflow.com/questions/10782187/how-to-encrypt-file-from-sd-card-using-aes-in-android Or https://stackoverflow.com/questions/13252956/how-to-encrypt-and-decrypt-folder-in-android-sdcard?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa – Farmer Mar 24 '18 at 12:36

2 Answers2

0

you can not encrypt Folders but you can encrypt files

take look at

http://www.codejava.net/coding/file-encryption-and-decryption-simple-example

keep in mind encrypting an decrypting is comes with costs of battery usage and time (depends on your file size you might even have lag on app).

you should only encrypt very important,sensitive data

if you don't want users access your file directly, you can store them in sqlite

  • Thank a lot for your answer but what is the best way to manage my requirement wich is to never let users open the files in the folder and only open and read the files programmatically? – Jean-Pascal MEWENEMESSE Mar 24 '18 at 13:00
0

Having done the research for your use case before, I can help you with my results and findings.

You can use symmetric algorithms for encryption and decryption. These symmetric encryption algorithms are relatively faster and consume fewer resources for computation.

You can read about symmetric cryptosystem here.

You will find lots of Java codes for each algorithm.

You need to ensure that the key used for symmetric encryption is not stored locally as users can Decompile the APK and access the code. For this, you can retrieve the keys for each user from public cloud database services like Firebase, etc.

So instead of encrypting the folder, you can encrypt your important docs and store them in the app's dedicated path.

In general, Other regular apps cannot access your app's dedicated path. Android won't allow that. But the users can browse through them using any file browser.

Read about Data and File Storage in Android here and choose the best suitable method for your use case.

Hope this is helpful.

pro_cheats
  • 1,534
  • 1
  • 15
  • 25
  • Great answer. Do you have some tutorials that shows how to manage my problem using symmetric cryptosystem in android? @pro_cheats – Jean-Pascal MEWENEMESSE Mar 24 '18 at 13:05
  • Sorry to say that we cannot spoonfeed you but, this can help you - http://www.oodlestechnologies.com/blogs/Encrypt-And-Decrypt-A-File-In-Java. Basically, everyone uses `java.crypto` package - https://docs.oracle.com/javase/7/docs/api/javax/crypto/package-summary.html – pro_cheats Mar 24 '18 at 13:19